com.levigo.util.swing
Class CollapsiblePane

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.levigo.util.swing.CollapsiblePane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
RolloutBox

public class CollapsiblePane
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.

 <code>
 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);
 </code>
 

Note: JCollapsiblePane requires its parent container to have a LayoutManager using getPreferredSize() when calculating its layout BorderLayout ).

Author:
rbair (from the JDNC project), Frederic Lavigne
See Also:
Serialized Form

Nested Class Summary
static interface CollapsiblePane.JCollapsiblePaneContainer
          Tagging interface for containers in a JCollapsiblePane hierarchy who needs to be revalidated (invalidate/validate/repaint) when the pane is expanding or collapsing.
static class CollapsiblePane.Style
          Enum for possible options regarding the strategy how a shrunken collapsible pane lays out its contents.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String ANIMATION_STATE_KEY
          Used when generating PropertyChangeEvents for the "animationState" property
static String COLLAPSED_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 COLLAPSED_NAME
          The name used by the "toggle" action when the JCollapsiblePane is expanded, i.e the name which indicates the pane can be collapsed.
static String EXPANDED_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 EXPANDED_NAME
          The name used by the "toggle" action when the JCollapsiblePane is collapsed, i.e the name which indicates the pane can be expanded.
static String TOGGLE_ACTION
          JCollapsible has a built-in toggle action which can be bound to buttons.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CollapsiblePane()
          Constructs a new JCollapsiblePane with a JPanel as content pane and a vertical with a gap of 2 pixels as layout manager.
CollapsiblePane(Container contentPane)
          Constructs a new JCollapsiblePane with a JPanel as content pane and a vertical with a gap of 2 pixels as layout manager.
 
Method Summary
protected  void addImpl(Component comp, Object constraints, int index)
           
 int getAnimationFPS()
           
 int getAnimationSteps()
           
 Border getBorder()
           
 Container getContentPanel()
           
 Insets getInsets()
           
 Insets getInsets(Insets insets)
           
 int getMaxAnimationStepSize()
           
 Dimension getMinimumSize()
           
 int getOrientation()
          Deprecated. Please use getStyle() instead.
 Dimension getPreferredSize()
          The critical part of the animation of this JCollapsiblePane relies on the calculation of its preferred size.
 CollapsiblePane.Style getStyle()
           
 boolean isAnimated()
           
 boolean isCollapsed()
           
protected  void paintBorder(Graphics g)
           
 void setAnimated(boolean animated)
          If true, enables the animation when pane is collapsed/expanded.
 void setAnimationFPS(int animationFPS)
           
 void setAnimationSteps(int animationSteps)
           
 void setBorder(Border border)
           
 void setBounds(int x, int y, int w, int h)
           
 void setCollapsed(boolean val)
          Expands or collapses this JCollapsiblePane.
 void setContentPane(Container contentPanel)
          Sets the content pane of this JCollapsiblePane.
 void setMaxAnimationStepSize(int maxAnimationStepSize)
           
 void setOrientation(int orientation)
          Deprecated. Please use setStyle(Style) instead.
 void setStyle(CollapsiblePane.Style style)
           
 
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, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, 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, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANIMATION_STATE_KEY

public static final String ANIMATION_STATE_KEY
Used when generating PropertyChangeEvents for the "animationState" property

See Also:
Constant Field Values

COLLAPSED_ICON

public static final String COLLAPSED_ICON
The icon used by the "toggle" action when the JCollapsiblePane is expanded, i.e the icon which indicates the pane can be collapsed.

See Also:
Constant Field Values

COLLAPSED_NAME

public static final String COLLAPSED_NAME
The name used by the "toggle" action when the JCollapsiblePane is expanded, i.e the name which indicates the pane can be collapsed.

See Also:
Constant Field Values

EXPANDED_ICON

public static final String EXPANDED_ICON
The icon used by the "toggle" action when the JCollapsiblePane is collapsed, i.e the icon which indicates the pane can be expanded.

See Also:
Constant Field Values

EXPANDED_NAME

public static final String EXPANDED_NAME
The name used by the "toggle" action when the JCollapsiblePane is collapsed, i.e the name which indicates the pane can be expanded.

See Also:
Constant Field Values

TOGGLE_ACTION

public static final String TOGGLE_ACTION
JCollapsible has a built-in toggle action which can be bound to buttons. Accesses the action through collapsiblePane.getActionMap().get(JCollapsiblePane.TOGGLE_ACTION) .

See Also:
Constant Field Values
Constructor Detail

CollapsiblePane

@CallOnEDT
public CollapsiblePane(Container contentPane)
Constructs a new JCollapsiblePane with a JPanel as content pane and a vertical with a gap of 2 pixels as layout manager.


CollapsiblePane

@CallOnEDT
public CollapsiblePane()
Constructs a new JCollapsiblePane with a JPanel as content pane and a vertical with a gap of 2 pixels as layout manager.

Method Detail

setBorder

@CallOnEDT
public void setBorder(Border border)
Overrides:
setBorder in class JComponent

paintBorder

protected void paintBorder(Graphics g)
Overrides:
paintBorder in class JComponent

getBorder

@CallOnEDT
public Border getBorder()
Overrides:
getBorder in class JComponent

getInsets

@CallOnEDT
public Insets getInsets(Insets insets)
Overrides:
getInsets in class JComponent

getInsets

@CallOnEDT
public Insets getInsets()
Overrides:
getInsets in class JComponent

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Overrides:
addImpl in class Container

setContentPane

@CallOnEDT
public void setContentPane(Container contentPanel)
Sets the content pane of this JCollapsiblePane. Components must be added to this content pane, not to the JCollapsiblePane.

Parameters:
contentPanel -
Throws:
IllegalArgumentException - if contentPanel is null

getContentPanel

@CallOnEDT
public Container getContentPanel()
Returns:
the content pane

setAnimated

@CallOnEDT
public void setAnimated(boolean animated)
If true, enables the animation when pane is collapsed/expanded. If false, animation is turned off.

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.

Parameters:
animated -

isAnimated

@CallOnEDT
public boolean isAnimated()
Returns:
true if the pane is animated, false otherwise
See Also:
setAnimated(boolean)

isCollapsed

@CallOnEDT
public boolean isCollapsed()
Returns:
true if the pane is collapsed, false if expanded

setCollapsed

@CallOnEDT
public void setCollapsed(boolean val)
Expands or collapses this 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.

See Also:
isAnimated(), setAnimated(boolean)

getMinimumSize

@CallOnEDT
public Dimension getMinimumSize()
Overrides:
getMinimumSize in class JComponent

getPreferredSize

@CallOnEDT
public Dimension getPreferredSize()
The critical part of the animation of this 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.

Overrides:
getPreferredSize in class JComponent
Returns:
this component preferred size

setBounds

@CallOnEDT
public final void setBounds(int x,
                                      int y,
                                      int w,
                                      int h)
Overrides:
setBounds in class Component

getOrientation

@Deprecated
@CallOnEDT
public int getOrientation()
Deprecated. Please use getStyle() instead.

Returns:
the orientation
See Also:
SwingConstants.HORIZONTAL, SwingConstants.VERTICAL

setOrientation

@Deprecated
@CallOnEDT
public void setOrientation(int orientation)
Deprecated. Please use setStyle(Style) instead.

Set the orientation

Parameters:
orientation - the orientation to set
See Also:
SwingConstants.HORIZONTAL, SwingConstants.VERTICAL

getAnimationSteps

@CallOnEDT
public int getAnimationSteps()
Returns:
the animationSteps

setAnimationSteps

@CallOnEDT
public void setAnimationSteps(int animationSteps)
Parameters:
animationSteps - the animationSteps to set

getMaxAnimationStepSize

@CallOnEDT
public int getMaxAnimationStepSize()
Returns:
the maxAnimationStepSize

setMaxAnimationStepSize

@CallOnEDT
public void setMaxAnimationStepSize(int maxAnimationStepSize)
Parameters:
maxAnimationStepSize - the maxAnimationStepSize to set

getAnimationFPS

@CallOnEDT
public int getAnimationFPS()
Returns:
the animationFPS

setAnimationFPS

@CallOnEDT
public void setAnimationFPS(int animationFPS)
Parameters:
animationFPS - the animationFPS to set

getStyle

@CallOnEDT
public CollapsiblePane.Style getStyle()
Returns:
the style

setStyle

@CallOnEDT
public void setStyle(CollapsiblePane.Style style)
Parameters:
style - the style to set


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.