Class JXCollapsiblePane
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.jdesktop.swingx.JXPanel
-
- org.jdesktop.swingx.JXCollapsiblePane
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.Scrollable,AlphaPaintable,BackgroundPaintable
@JavaBean public class JXCollapsiblePane extends JXPanel
JXCollapsiblePaneprovides 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
JXCollapsiblePanehas 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.
For convenience, the// to set the font collapsiblePane.getContentPane().setFont(font); // to set the background color collapsiblePane.getContentPane().setBackground(Color.RED);addandremovemethods forward to the content pane. The following code shows to ways to add a child to the content pane.
To set the content pane, do not use// to add a child collapsiblePane.getContentPane().add(component); // to add a child collapsiblePane.add(component);add, usesetContentPane(Container).In this example, the
JXCollapsiblePaneis 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
JXCollapsiblePanehas a default toggle action registered under the nameTOGGLE_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 theEXPAND_ICONandCOLLAPSE_ICONproperties 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:
JXCollapsiblePanerequires its parent container to have aLayoutManagerusinggetPreferredSize()when calculating its layout (exampleVerticalLayout,BorderLayout).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classJXCollapsiblePane.AnimationListenerThis class actual provides the animation support for scrolling up/down this component.private static classJXCollapsiblePane.AnimationParamsParameters controlling the animationsstatic interfaceJXCollapsiblePane.CollapsiblePaneContainerTagging interface for containers in a JXCollapsiblePane hierarchy who needs to be revalidated (invalidate/validate/repaint) when the pane is expanding or collapsing.static classJXCollapsiblePane.DirectionThe direction defines how the collapsible pane will collapse.private classJXCollapsiblePane.ToggleActionToggles the JXCollapsiblePane state and updates its icon based on the JXCollapsiblePane "collapsed" status.private classJXCollapsiblePane.WrapperContainer-
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.TimeranimateTimerTimer used for doing the transparency animation (fade-in)private JXCollapsiblePane.AnimationParamsanimationParamsprivate JXCollapsiblePane.AnimationListeneranimatorstatic java.lang.StringCOLLAPSE_ICONThe icon used by the "toggle" action when the JXCollapsiblePane is expanded, i.e the icon which indicates the pane can be collapsed.private booleancollapsedIndicates whether the component is collapsed or expandedprivate booleancollapseFiringStateprivate intcurrentDimensionprivate JXCollapsiblePane.DirectiondirectionDefines the orientation of the component.static java.lang.StringEXPAND_ICONThe icon used by the "toggle" action when the JXCollapsiblePane is collapsed, i.e the icon which indicates the pane can be expanded.static java.lang.StringTOGGLE_ACTIONJXCollapsible has a built-in toggle action which can be bound to buttons.private booleanuseAnimationprivate JXCollapsiblePane.WrapperContainerwrapper-
Fields inherited from class org.jdesktop.swingx.JXPanel
fakeTransparent
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description JXCollapsiblePane()Constructs a new JXCollapsiblePane with aJXPanelas content pane and a verticalVerticalLayoutwith a gap of 2 pixels as layout manager and a vertical orientation.JXCollapsiblePane(JXCollapsiblePane.Direction direction)Constructs a new JXCollapsiblePane with aJXPanelas content pane and the specified direction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddImpl(java.awt.Component comp, java.lang.Object constraints, int index)Overridden to redirect call to the content pane.protected java.awt.ContainercreateContentPane()Creates the content pane used by this collapsible pane.javax.swing.border.BordergetBorder()java.awt.ContainergetContentPane()JXCollapsiblePane.DirectiongetDirection()java.awt.DimensiongetMinimumSize()A collapsible pane always returns its preferred size for the minimum size to ensure that the collapsing happens correctly.java.awt.DimensiongetPreferredSize()The critical part of the animation of thisJXCollapsiblePanerelies on the calculation of its preferred size.booleanisAnimated()booleanisCollapsed()voidremove(int index)Overridden to redirect call to the content pane.voidremove(java.awt.Component comp)Overridden to redirect call to the content panevoidremoveAll()Overridden to redirect call to the content pane.voidsetAnimated(boolean animated)If true, enables the animation when pane is collapsed/expanded.private voidsetAnimationParams(JXCollapsiblePane.AnimationParams params)Sets the parameters controlling the animationvoidsetBorder(javax.swing.border.Border border)voidsetCollapsed(boolean val)Expands or collapses thisJXCollapsiblePane.voidsetComponentOrientation(java.awt.ComponentOrientation o)voidsetContentPane(java.awt.Container contentPanel)Sets the content pane of this JXCollapsiblePane.voidsetDirection(JXCollapsiblePane.Direction direction)Changes the direction of this collapsible pane.voidsetLayout(java.awt.LayoutManager mgr)Overridden to redirect call to the content pane.voidsetMinimumSize(java.awt.Dimension minimumSize)Forwards to the content pane.voidsetOpaque(boolean opaque)voidsetPreferredSize(java.awt.Dimension preferredSize)-
Methods inherited from class org.jdesktop.swingx.JXPanel
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, installRepaintManager, isAlpha, isInheritAlpha, isOpaque, isOpaquePatch, isPaintBorderInsets, isPaintingBackground, isPaintingOrigin, isPatch, isTransparentBackground, paint, paintComponent, paintComponentPatch, setAlpha, setBackgroundPainter, setInheritAlpha, setOpaquePatch, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint, uninstallRepaintManager
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
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, isOptimizedDrawingEnabled, isPaintingForPrint, 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, setBackground, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setNextFocusableComponent, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
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
-
Methods inherited from class java.awt.Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
TOGGLE_ACTION
public static final java.lang.String TOGGLE_ACTION
JXCollapsible has a built-in toggle action which can be bound to buttons. Accesses the action throughcollapsiblePane.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION).- See Also:
- Constant Field Values
-
COLLAPSE_ICON
public static final java.lang.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.- See Also:
- Constant Field Values
-
EXPAND_ICON
public static final java.lang.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.- See Also:
- Constant Field Values
-
collapsed
private boolean collapsed
Indicates whether the component is collapsed or expanded
-
direction
private JXCollapsiblePane.Direction direction
Defines the orientation of the component.
-
animateTimer
private javax.swing.Timer animateTimer
Timer used for doing the transparency animation (fade-in)
-
animator
private JXCollapsiblePane.AnimationListener animator
-
currentDimension
private int currentDimension
-
wrapper
private JXCollapsiblePane.WrapperContainer wrapper
-
useAnimation
private boolean useAnimation
-
animationParams
private JXCollapsiblePane.AnimationParams animationParams
-
collapseFiringState
private boolean collapseFiringState
-
-
Constructor Detail
-
JXCollapsiblePane
public JXCollapsiblePane()
Constructs a new JXCollapsiblePane with aJXPanelas content pane and a verticalVerticalLayoutwith a gap of 2 pixels as layout manager and a vertical orientation.
-
JXCollapsiblePane
public JXCollapsiblePane(JXCollapsiblePane.Direction direction)
Constructs a new JXCollapsiblePane with aJXPanelas content pane and the specified direction.- Parameters:
direction- the direction to collapse the container
-
-
Method Detail
-
createContentPane
protected java.awt.Container createContentPane()
Creates the content pane used by this collapsible pane.- Returns:
- the content pane
-
getContentPane
public java.awt.Container getContentPane()
- Returns:
- the content pane
-
setContentPane
public void setContentPane(java.awt.Container contentPanel)
Sets the content pane of this JXCollapsiblePane. ThecontentPanelshould implementScrollableand returntruefromScrollable.getScrollableTracksViewportHeight()andScrollable.getScrollableTracksViewportWidth(). If the content pane fails to do so and aJScrollPaneis added as a child, it is likely that the scroll pane will never correctly size. While it is not strictly necessary to implementScrollablein this way, the default content pane does so.- Parameters:
contentPanel- the container delegate used to hold all of the contents for this collapsible pane- Throws:
java.lang.IllegalArgumentException- if contentPanel is null
-
setLayout
public void setLayout(java.awt.LayoutManager mgr)
Overridden to redirect call to the content pane.- Overrides:
setLayoutin classjava.awt.Container
-
addImpl
protected void addImpl(java.awt.Component comp, java.lang.Object constraints, int index)Overridden to redirect call to the content pane.- Overrides:
addImplin classjava.awt.Container
-
remove
public void remove(java.awt.Component comp)
Overridden to redirect call to the content pane- Overrides:
removein classjava.awt.Container
-
remove
public void remove(int index)
Overridden to redirect call to the content pane.- Overrides:
removein classjava.awt.Container
-
removeAll
public void removeAll()
Overridden to redirect call to the content pane.- Overrides:
removeAllin classjava.awt.Container
-
setAnimated
public void setAnimated(boolean animated)
If true, enables the animation when pane is collapsed/expanded. If false, animation is turned off.When animated, the
JXCollapsiblePanewill 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
JXCollapsiblePanewill simply hide (collapsing) or show (expanding) its content area.- Parameters:
animated-
-
isAnimated
public boolean isAnimated()
- Returns:
- true if the pane is animated, false otherwise
- See Also:
setAnimated(boolean)
-
setComponentOrientation
public void setComponentOrientation(java.awt.ComponentOrientation o)
- Overrides:
setComponentOrientationin classjava.awt.Component
-
setDirection
public void setDirection(JXCollapsiblePane.Direction direction)
Changes the direction of this collapsible pane. Doing so changes the layout of the underlying content pane. If the chosen direction 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:
direction- the newJXCollapsiblePane.Directionfor this collapsible pane- Throws:
java.lang.IllegalStateException- when this method is called while a collapsing/restore operation is running- See Also:
getDirection()
-
getDirection
public JXCollapsiblePane.Direction getDirection()
- Returns:
- the current
JXCollapsiblePane.Direction. - See Also:
setDirection(Direction)
-
isCollapsed
public boolean isCollapsed()
- Returns:
- true if the pane is collapsed, false if expanded
-
setCollapsed
public void setCollapsed(boolean val)
Expands or collapses thisJXCollapsiblePane.If the component is collapsed and
valis false, then this call expands the JXCollapsiblePane, such that the entire JXCollapsiblePane will be visible. IfisAnimated()returns true, the expansion will be accompanied by an animation.However, if the component is expanded and
valis true, then this call collapses the JXCollapsiblePane, such that the entire JXCollapsiblePane will be invisible. IfisAnimated()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.
- See Also:
isAnimated(),setAnimated(boolean)
-
getBorder
public javax.swing.border.Border getBorder()
- Overrides:
getBorderin classjavax.swing.JComponent
-
setBorder
public void setBorder(javax.swing.border.Border border)
- Overrides:
setBorderin classjavax.swing.JComponent
-
setOpaque
public void setOpaque(boolean opaque)
Setting the component to be opaque will reset the alpha setting to
1f(full opaqueness). Setting the component to be non-opaque will restore the previous alpha transparency. If the component is non-opaque with a fully-opaque alpha value (1f), the behavior should be the same as as aJPanelthat is non-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 thecontent pane, as it is not considered an internal.
-
getMinimumSize
public java.awt.Dimension getMinimumSize()
A collapsible pane always returns its preferred size for the minimum size to ensure that the collapsing happens correctly.To query the minimum size of the contents user
getContentPane().getMinimumSize().- Overrides:
getMinimumSizein classjavax.swing.JComponent- Returns:
- the preferred size of the component
-
setMinimumSize
public void setMinimumSize(java.awt.Dimension minimumSize)
Forwards to the content pane.- Overrides:
setMinimumSizein classjavax.swing.JComponent- Parameters:
minimumSize- the size to set on the content pane
-
getPreferredSize
public java.awt.Dimension getPreferredSize()
The critical part of the animation of thisJXCollapsiblePanerelies 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.- Overrides:
getPreferredSizein classjavax.swing.JComponent- Returns:
- this component preferred size
-
setPreferredSize
public void setPreferredSize(java.awt.Dimension preferredSize)
- Overrides:
setPreferredSizein classjavax.swing.JComponent
-
setAnimationParams
private void setAnimationParams(JXCollapsiblePane.AnimationParams params)
Sets the parameters controlling the animation- Parameters:
params-- Throws:
java.lang.IllegalArgumentException- if params is null
-
-