public class JCollapsiblePane extends JPanel
JCollapsiblePane 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 JCollapsiblePane is used to build a Search
pane which can be shown and hidden on demand.
JCollapsiblePane cp = new JCollapsiblePane();
// JCollapsiblePane 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);
JFrame frame = new JFrame();
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(JCollapsiblePane.TOGGLE_ACTION));
toggle.setText("Show/Hide Search Panel");
frame.add("South", toggle);
frame.pack();
frame.setVisible(true);
Note: JCollapsiblePane requires its parent container to have a
LayoutManager using getPreferredSize() when
calculating its layout (example PercentLayout,
BorderLayout).
| Modifier and Type | Class and Description |
|---|---|
static interface |
JCollapsiblePane.JCollapsiblePaneContainer
Tagging interface for containers in a JCollapsiblePane hierarchy who
needs to be revalidated (invalidate/validate/repaint) when the pane is
expanding or collapsing.
|
JPanel.AccessibleJPanelJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static String |
ANIMATION_STATE_KEY
Used when generating PropertyChangeEvents for the "animationState"
property
|
static String |
COLLAPSE_ICON
The icon used by the "toggle" action when the JCollapsiblePane is
expanded, i.e the icon which indicates the pane can be collapsed.
|
static String |
EXPAND_ICON
The icon used by the "toggle" action when the JCollapsiblePane is
collapsed, i.e the icon which indicates the pane can be expanded.
|
static String |
TOGGLE_ACTION
JCollapsible has a built-in toggle action which can be bound to buttons.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JCollapsiblePane()
Constructs a new JCollapsiblePane with a
JPanel as content pane
and a vertical PercentLayout with a gap of 2 pixels as layout
manager. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addImpl(Component comp,
Object constraints,
int index)
Overriden to redirect call to the content pane.
|
Container |
getContentPane() |
Dimension |
getMinimumSize() |
Dimension |
getPreferredSize()
The critical part of the animation of this
JCollapsiblePane
relies on the calculation of its preferred size. |
boolean |
isAnimated() |
boolean |
isCollapsed() |
void |
remove(Component comp)
Overriden to redirect call to the content pane
|
void |
remove(int index)
Overriden to redirect call to the content pane.
|
void |
removeAll()
Overriden to redirect call to the content pane.
|
void |
setAnimated(boolean animated)
If true, enables the animation when pane is collapsed/expanded.
|
void |
setCollapsed(boolean val)
Expands or collapses this
JCollapsiblePane. |
void |
setContentPane(Container contentPanel)
Sets the content pane of this JCollapsiblePane.
|
void |
setLayout(LayoutManager mgr)
Overriden to redirect call to the content pane.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, 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, paint, paintBorder, paintChildren, paintComponent, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, 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, validateTreeaction, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final String ANIMATION_STATE_KEY
public static final String TOGGLE_ACTION
collapsiblePane.getActionMap().get(JCollapsiblePane.TOGGLE_ACTION).public static final String COLLAPSE_ICON
public static final String EXPAND_ICON
public JCollapsiblePane()
JPanel as content pane
and a vertical PercentLayout with a gap of 2 pixels as layout
manager.public void setContentPane(Container contentPanel)
contentPanel - IllegalArgumentException - if contentPanel is nullpublic Container getContentPane()
public void setLayout(LayoutManager mgr)
protected void addImpl(Component comp, Object constraints, int index)
public void remove(Component comp)
public void remove(int index)
public void removeAll()
public void setAnimated(boolean animated)
When animated, the JCollapsiblePane 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 JCollapsiblePane will simply hide
(collapsing) or show (expanding) its content area.
animated - public boolean isAnimated()
setAnimated(boolean)public boolean isCollapsed()
public void setCollapsed(boolean val)
JCollapsiblePane.
If the component is collapsed and val is false, then this
call expands the JCollapsiblePane, such that the entire JCollapsiblePane
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 JCollapsiblePane, such that the entire
JCollapsiblePane will be invisible. If isAnimated() returns
true, the collapse will be accompanied by an animation.
val - isAnimated(),
setAnimated(boolean)public Dimension getMinimumSize()
getMinimumSize in class JComponentpublic Dimension getPreferredSize()
JCollapsiblePane
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 JComponentCopyright © 2015. All rights reserved.