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

accesstypenameparameters

[show]methods inherited from org.jdesktop.swingx.JXCollapsiblePane

addImpl, remove, remove, removeAll,

[show]methods inherited from org.jdesktop.swingx.JXPanel

paint, paintComponent,

[show]methods inherited from javax.swing.JPanel

paramString, updateUI,

[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,

[show]methods inherited from java.lang.Object

clone, equals, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait,

Fields

staticaccesstypename
staticpublicStringANIMATION_STATE_KEY
staticpublicStringTOGGLE_ACTION
staticpublicStringCOLLAPSE_ICON
staticpublicStringEXPAND_ICON

static public String ANIMATION_STATE_KEY

Used when generating PropertyChangeEvents for the "animationState" property. The PropertyChangeEvent will takes the following different values for java.beans.PropertyChangeEventgetNewValue(): reinit every time the animation starts expanded when the animation ends and the pane is expanded collapsed when the animation ends and the pane is collapsed

static public String TOGGLE_ACTION

JXCollapsible has a built-in toggle action which can be bound to buttons. Accesses the action through collapsiblePane.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION).

static public 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.

static public 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.

Constructors

accessnameparameters
publicJXCollapsiblePane ()
publicJXCollapsiblePane (JXCollapsiblePane.Orientation orientation, )
publicJXCollapsiblePane (LayoutManager layout, )
publicJXCollapsiblePane (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

    nametypedescriptionget/setaccessinheritedbound
    contentPanevoid-----public----
    layoutvoid-----public----
    preferredSizeDimension-----public----
    collapsedboolean-----public----
    minimumSizeDimension-----public----
    orientationvoid-----public----
    animatedvoid-----public----

    [show]properties inherited from org.jdesktop.swingx.JXCollapsiblePane

    animated , collapsed , contentPane , layout , minimumSize , orientation , preferredSize ,

    [show]properties inherited from javax.swing.JPanel

    accessibleContext , uI , uIClassID ,

    [show]properties inherited from java.lang.Object

    class ,

    contentPane

    public void setContentPane (Container contentPanel, )

    Sets the content pane of this JXCollapsiblePane.

    Parameters
    • contentPanel

    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 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

      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

      Static and Factory Methods