Overview
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.
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 org.jdesktop.swingx.JXCollapsiblePaneTOGGLE_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 org.jdesktop.swingx.JXCollapsiblePaneEXPAND_ICON and org.jdesktop.swingx.JXCollapsiblePaneCOLLAPSE_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
java.awt.LayoutManager using org.jdesktop.swingx.JXCollapsiblePanegetPreferredSize() when
calculating its layout (example org.jdesktop.swingx.VerticalLayout,
java.awt.BorderLayout).
Author(s):
General Methods
access | type | name | parameters |
---|
[show]methods inherited from org.jdesktop.swingx.JXCollapsiblePane
[show]methods inherited from org.jdesktop.swingx.JXPanel
[show]methods inherited from javax.swing.JPanel
[show]methods inherited from javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, grabFocus, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, unregisterKeyboardAction, update, updateUI,
[show]methods inherited from java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, insets, invalidate, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree,
[show]methods inherited from java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate,
Fields
static | access | type | name |
---|---|---|---|
static | public | String | ANIMATION_STATE_KEY |
static | public | String | TOGGLE_ACTION |
static | public | String | COLLAPSE_ICON |
static | public | String | EXPAND_ICON |
static public String ANIMATION_STATE_KEY
static public String TOGGLE_ACTION
static public String COLLAPSE_ICON
static public String EXPAND_ICON
Constructors
access | name | parameters |
---|---|---|
public | JXCollapsiblePane | () |
public | JXCollapsiblePane |
(JXCollapsiblePane.Orientation orientation , )
|
public | JXCollapsiblePane |
(LayoutManager layout , )
|
public | JXCollapsiblePane |
(JXCollapsiblePane.Orientation orientation , LayoutManager layout , )
|
public JXCollapsiblePane
()
Constructs a new JXCollapsiblePane with a javax.swing.JPanel as content pane and a vertical VerticalLayout with a gap of 2 pixels as layout manager and a vertical orientation.
Parameters
public JXCollapsiblePane
(JXCollapsiblePane.Orientation orientation
, )
Constructs a new JXCollapsiblePane with a javax.swing.JPanel as content pane and the specified orientation.
Parameters
- orientation
public JXCollapsiblePane
(LayoutManager layout
, )
Constructs a new JXCollapsiblePane with a javax.swing.JPanel as content pane and the given LayoutManager and a vertical orientation
Parameters
- layout
public JXCollapsiblePane
(JXCollapsiblePane.Orientation orientation
, LayoutManager layout
, )
Constructs a new JXCollapsiblePane with a javax.swing.JPanel as content pane and the given LayoutManager and orientation. A vertical orientation enables a vertical VerticalLayout with a gap of 2 pixels as layout manager. A horizontal orientation enables a horizontal HorizontalLayout with a gap of 2 pixels as layout manager
Parameters
- orientation
- layout
Properties
name | type | description | get/set | access | inherited | bound |
---|---|---|---|---|---|---|
contentPane | void | --- | -- | public | -- | -- |
layout | void | --- | -- | public | -- | -- |
preferredSize | Dimension | --- | -- | public | -- | -- |
collapsed | boolean | --- | -- | public | -- | -- |
minimumSize | Dimension | --- | -- | public | -- | -- |
orientation | void | --- | -- | public | -- | -- |
animated | void | --- | -- | public | -- | -- |
[show]properties inherited from org.jdesktop.swingx.JXCollapsiblePane
animated , collapsed , contentPane , layout , minimumSize , orientation , preferredSize ,
[show]properties inherited from org.jdesktop.swingx.JXPanel
alpha , backgroundPainter , effectiveAlpha , foregroundPainter , inheritAlpha , painterSet , preferredScrollableViewportSize , scrollableBlockIncrement , scrollableTracksViewportHeight , scrollableTracksViewportWidth , scrollableUnitIncrement ,
[show]properties inherited from javax.swing.JPanel
[show]properties inherited from javax.swing.JComponent
accessibleContext , actionForKeyStroke , actionMap , alignmentX , alignmentY , ancestorListeners , autoscrolls , background , border , bounds , clientProperty , componentGraphics , componentPopupMenu , conditionForKeyStroke , debugGraphicsOptions , defaultLocale , doubleBuffered , enabled , focusTraversalKeys , font , fontMetrics , foreground , graphics , height , inheritsPopupMenu , inputMap , inputVerifier , insets , lightweightComponent , listeners , location , managingFocus , maximumSize , minimumSize , nextFocusableComponent , opaque , optimizedDrawingEnabled , paintingTile , popupLocation , preferredSize , registeredKeyStrokes , requestFocusEnabled , rootPane , size , toolTipLocation , toolTipText , topLevelAncestor , transferHandler , uI , uIClassID , validateRoot , verifyInputWhenFocusTarget , vetoableChangeListeners , visible , visibleRect , width , x , y ,
[show]properties inherited from java.awt.Container
alignmentX , alignmentY , ancestorOf , component , componentAt , componentCount , components , componentZOrder , containerListeners , focusCycleRoot , focusTraversalKeys , focusTraversalPolicy , focusTraversalPolicyProvider , focusTraversalPolicySet , font , insets , layout , listeners , maximumSize , minimumSize , mousePosition , preferredSize ,
[show]properties inherited from java.awt.Component
accessibleContext , alignmentX , alignmentY , background , backgroundSet , bounds , colorModel , componentAt , componentListeners , componentOrientation , cursor , cursorSet , displayable , doubleBuffered , dropTarget , enabled , focusable , focusCycleRoot , focusCycleRootAncestor , focusListeners , focusOwner , focusTraversable , focusTraversalKeys , focusTraversalKeysEnabled , font , fontMetrics , fontSet , foreground , foregroundSet , graphics , graphicsConfiguration , height , hierarchyBoundsListeners , hierarchyListeners , ignoreRepaint , inputContext , inputMethodListeners , inputMethodRequests , keyListeners , lightweight , listeners , locale , location , locationOnScreen , maximumSize , maximumSizeSet , minimumSize , minimumSizeSet , mouseListeners , mouseMotionListeners , mousePosition , mouseWheelListeners , name , opaque , parent , peer , preferredSize , preferredSizeSet , propertyChangeListeners , showing , size , toolkit , treeLock , valid , visible , width , x , y ,
contentPane
public void setContentPane
(Container contentPanel
, )
Sets the content pane of this JXCollapsiblePane.
Parameters
- contentPanel
public Container getContentPane
()
Parameters
layout
public void setLayout
(LayoutManager mgr
, )
Overriden to redirect call to the content pane.
Parameters
- mgr
preferredSize
public Dimension getPreferredSize
()
The critical part of the animation of this 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.
Parameters
collapsed
public boolean isCollapsed
()
Parameters
public void setCollapsed
(boolean val
, )
Expands or collapses this 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 org.jdesktop.swingx.JXCollapsiblePaneisAnimated() 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 org.jdesktop.swingx.JXCollapsiblePaneisAnimated() returns true, the collapse will be accompanied by an animation.
Parameters
- val
minimumSize
public Dimension getMinimumSize
()
Parameters
orientation
public void setOrientation
(JXCollapsiblePane.Orientation orientation
, )
Changes the orientation of this collapsible pane. Doing so changes the layout of the underlying content pane. If the chosen orientation is vertical, a vertical layout with a gap of 2 pixels is chosen. Otherwise, a horizontal layout with a gap of 2 pixels is chosen.
Parameters
- orientation the new {@link Orientation} for this collapsible pane
animated
public void setAnimated
(boolean animated
, )
If true, enables the animation when pane is collapsed/expanded. If false, animation is turned off. 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.
Parameters
- animated