public class JXCollapsiblePane extends JXPanel
JXCollapsiblePane
provides a component which can collapse or
expand its content area with animation and fade in/fade out effects.
It also acts as a standard container for other Swing components.
The JXCollapsiblePane
has a "content pane" that actually holds the
displayed contents. This means that colors, fonts, and other display
configuration items must be set on the content pane.
// to set the font
collapsiblePane.getContentPane().setFont(font);
// to set the background color
collapsiblePane.getContentPane().setBackground(Color.RED);
For convenience, the add
and remove
methods forward to the
content pane. The following code shows to ways to add a child to the
content pane.
// to add a child
collapsiblePane.getContentPane().add(component);
// to add a child
collapsiblePane.add(component);
To set the content pane, do not use add
, use setContentPane(Container)
.
In this example, the JXCollapsiblePane
is used to build
a Search pane which can be shown and hidden on demand.
JXCollapsiblePane cp = new JXCollapsiblePane();
// JXCollapsiblePane can be used like any other container
cp.setLayout(new BorderLayout());
// the Controls panel with a textfield to filter the tree
JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 0));
controls.add(new JLabel("Search:"));
controls.add(new JTextField(10));
controls.add(new JButton("Refresh"));
controls.setBorder(new TitledBorder("Filters"));
cp.add("Center", controls);
JXFrame frame = new JXFrame();
frame.setLayout(new BorderLayout());
// Put the "Controls" first
frame.add("North", cp);
// Then the tree - we assume the Controls would somehow filter the tree
JScrollPane scroll = new JScrollPane(new JTree());
frame.add("Center", scroll);
// Show/hide the "Controls"
JButton toggle = new JButton(cp.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION));
toggle.setText("Show/Hide Search Panel");
frame.add("South", toggle);
frame.pack();
frame.setVisible(true);
The JXCollapsiblePane
has a default toggle action registered
under the name TOGGLE_ACTION
. Bind this action to a button and
pressing the button will automatically toggle the pane between expanded
and collapsed states. Additionally, you can define the icons to use through
the EXPAND_ICON
and COLLAPSE_ICON
properties on the action.
Example
// get the built-in toggle action
Action toggleAction = collapsible.getActionMap().
get(JXCollapsiblePane.TOGGLE_ACTION);
// use the collapse/expand icons from the JTree UI
toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON,
UIManager.getIcon("Tree.expandedIcon"));
toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON,
UIManager.getIcon("Tree.collapsedIcon"));
Note: JXCollapsiblePane
requires its parent container to have a
LayoutManager
using getPreferredSize()
when
calculating its layout (example VerticalLayout
,
BorderLayout
).
Modifier and Type | Class and Description |
---|---|
private class |
JXCollapsiblePane.AnimationListener
This class actual provides the animation support for scrolling up/down this
component.
|
private static class |
JXCollapsiblePane.AnimationParams
Parameters controlling the animations
|
static interface |
JXCollapsiblePane.CollapsiblePaneContainer
Tagging interface for containers in a JXCollapsiblePane hierarchy who needs
to be revalidated (invalidate/validate/repaint) when the pane is expanding
or collapsing.
|
static class |
JXCollapsiblePane.Direction
The direction defines how the collapsible pane will collapse.
|
private class |
JXCollapsiblePane.ToggleAction
Toggles the JXCollapsiblePane state and updates its icon based on the
JXCollapsiblePane "collapsed" status.
|
private class |
JXCollapsiblePane.WrapperContainer |
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private Timer |
animateTimer
Timer used for doing the transparency animation (fade-in)
|
private JXCollapsiblePane.AnimationParams |
animationParams |
private JXCollapsiblePane.AnimationListener |
animator |
static String |
COLLAPSE_ICON
The icon used by the "toggle" action when the JXCollapsiblePane is
expanded, i.e the icon which indicates the pane can be collapsed.
|
private boolean |
collapsed
Indicates whether the component is collapsed or expanded
|
private boolean |
collapseFiringState |
private int |
currentDimension |
private JXCollapsiblePane.Direction |
direction
Defines the orientation of the component.
|
static String |
EXPAND_ICON
The icon used by the "toggle" action when the JXCollapsiblePane is
collapsed, i.e the icon which indicates the pane can be expanded.
|
static String |
TOGGLE_ACTION
JXCollapsible has a built-in toggle action which can be bound to buttons.
|
private boolean |
useAnimation |
private JXCollapsiblePane.WrapperContainer |
wrapper |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXCollapsiblePane()
Constructs a new JXCollapsiblePane with a
JXPanel as content pane
and a vertical VerticalLayout with a gap of 2 pixels as layout
manager and a vertical orientation. |
JXCollapsiblePane(JXCollapsiblePane.Direction direction)
Constructs a new JXCollapsiblePane with a
JXPanel as content pane and the specified
direction. |
Modifier and Type | Method and Description |
---|---|
protected void |
addImpl(Component comp,
Object constraints,
int index)
Overridden to redirect call to the content pane.
|
Border |
getBorder() |
Container |
getContentPane() |
JXCollapsiblePane.Direction |
getDirection() |
Dimension |
getMinimumSize()
A collapsible pane always returns its preferred size for the minimum size
to ensure that the collapsing happens correctly.
|
Dimension |
getPreferredSize()
The critical part of the animation of this
JXCollapsiblePane
relies on the calculation of its preferred size. |
boolean |
isAnimated() |
boolean |
isCollapsed() |
void |
remove(Component comp)
Overridden to redirect call to the content pane
|
void |
remove(int index)
Overridden to redirect call to the content pane.
|
void |
removeAll()
Overridden to redirect call to the content pane.
|
void |
setAnimated(boolean animated)
If true, enables the animation when pane is collapsed/expanded.
|
private void |
setAnimationParams(JXCollapsiblePane.AnimationParams params)
Sets the parameters controlling the animation
|
void |
setBorder(Border border) |
void |
setCollapsed(boolean val)
Expands or collapses this
JXCollapsiblePane . |
void |
setComponentOrientation(ComponentOrientation o) |
void |
setContentPane(Container contentPanel)
Sets the content pane of this JXCollapsiblePane.
|
void |
setDirection(JXCollapsiblePane.Direction direction)
Changes the direction of this collapsible pane.
|
void |
setLayout(LayoutManager mgr)
Overridden to redirect call to the content pane.
|
void |
setMinimumSize(Dimension minimumSize)
Forwards to the content pane.
|
void |
setOpaque(boolean opaque)
Internals of JXCollasiplePane are designed to be opaque because some Look and Feel
implementations having painting issues otherwise.
|
void |
setPreferredSize(Dimension preferredSize) |
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, installRepaintManager, isInheritAlpha, isPaintBorderInsets, paint, paintComponent, setAlpha, setBackground, setBackgroundPainter, setInheritAlpha, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint, uninstallRepaintManager
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setNextFocusableComponent, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final String TOGGLE_ACTION
collapsiblePane.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)
.public static final String COLLAPSE_ICON
public static final String EXPAND_ICON
private boolean collapsed
private JXCollapsiblePane.Direction direction
private Timer animateTimer
private JXCollapsiblePane.AnimationListener animator
private int currentDimension
private JXCollapsiblePane.WrapperContainer wrapper
private boolean useAnimation
private JXCollapsiblePane.AnimationParams animationParams
private boolean collapseFiringState
public JXCollapsiblePane()
JXPanel
as content pane
and a vertical VerticalLayout
with a gap of 2 pixels as layout
manager and a vertical orientation.public JXCollapsiblePane(JXCollapsiblePane.Direction direction)
JXPanel
as content pane and the specified
direction.direction
- the direction to collapse the containerpublic void setContentPane(Container contentPanel)
contentPanel
should implement Scrollable
and return true
from
Scrollable.getScrollableTracksViewportHeight()
and
Scrollable.getScrollableTracksViewportWidth()
. If the content
pane fails to do so and a JScrollPane
is added as a child, it is
likely that the scroll pane will never correctly size. While it is not
strictly necessary to implement Scrollable
in this way, the
default content pane does so.contentPanel
- the container delegate used to hold all of the contents
for this collapsible paneIllegalArgumentException
- if contentPanel is nullpublic Container getContentPane()
public void setLayout(LayoutManager mgr)
protected void addImpl(Component comp, Object constraints, int index)
public void remove(int index)
public void removeAll()
public void setAnimated(boolean animated)
When animated, the JXCollapsiblePane
will progressively
reduce (when collapsing) or enlarge (when expanding) the height of its
content area until it becomes 0 or until it reaches the preferred height of
the components it contains. The transparency of the content area will also
change during the animation.
If not animated, the JXCollapsiblePane
will simply hide
(collapsing) or show (expanding) its content area.
animated
- public boolean isAnimated()
setAnimated(boolean)
public void setComponentOrientation(ComponentOrientation o)
setComponentOrientation
in class Component
public void setDirection(JXCollapsiblePane.Direction direction)
direction
- the new JXCollapsiblePane.Direction
for this collapsible paneIllegalStateException
- when this method is called while a
collapsing/restore operation is runninggetDirection()
public JXCollapsiblePane.Direction getDirection()
JXCollapsiblePane.Direction
.setDirection(Direction)
public boolean isCollapsed()
public void setCollapsed(boolean val)
JXCollapsiblePane
.
If the component is collapsed and val
is false, then this
call expands the JXCollapsiblePane, such that the entire JXCollapsiblePane
will be visible. If isAnimated()
returns true, the expansion will
be accompanied by an animation.
However, if the component is expanded and val
is true, then
this call collapses the JXCollapsiblePane, such that the entire
JXCollapsiblePane will be invisible. If isAnimated()
returns true,
the collapse will be accompanied by an animation.
As of SwingX 1.6.3, JXCollapsiblePane only fires property change events when the component's state is accurate. This means that animated collapsible pane's only fire events once the animation is complete.
isAnimated()
,
setAnimated(boolean)
public Border getBorder()
getBorder
in class JComponent
public void setBorder(Border border)
setBorder
in class JComponent
public void setOpaque(boolean opaque)
Internals of JXCollasiplePane are designed to be opaque because some Look and Feel
implementations having painting issues otherwise. JXCollapsiblePane and its internals will
respect setOpaque
, calling this method will not only update the collapsible pane, but
also all internals. This method does not modify the content pane
,
as it is not considered an internal.
setOpaque
in class JComponent
public Dimension getMinimumSize()
To query the minimum size of the contents user getContentPane().getMinimumSize()
.
getMinimumSize
in class JComponent
public void setMinimumSize(Dimension minimumSize)
setMinimumSize
in class JComponent
minimumSize
- the size to set on the content panepublic Dimension getPreferredSize()
JXCollapsiblePane
relies on the calculation of its preferred size. During the animation, its
preferred size (specially its height) will change, when expanding, from 0
to the preferred size of the content pane, and the reverse when collapsing.getPreferredSize
in class JComponent
public void setPreferredSize(Dimension preferredSize)
setPreferredSize
in class JComponent
private void setAnimationParams(JXCollapsiblePane.AnimationParams params)
params
- IllegalArgumentException
- if params is nullWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses