|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.jdesktop.swingx.JXPanel
org.jdesktop.swingx.JXCollapsiblePane
public class JXCollapsiblePane
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.
The JXCollapsiblePane has 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.
// to set the font
collapsiblePane.getContentPane().setFont(font);
// to set the background color
collapsiblePane.getContentPane().setBackground(Color.RED);
For convenience, the add and remove methods forward to the
content pane. The following code shows to ways to add a child to the
content pane.
// to add a child
collapsiblePane.getContentPane().add(component);
// to add a child
collapsiblePane.add(component);
To set the content pane, do not use add, use setContentPane(Container).
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 TOGGLE_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 EXPAND_ICON and COLLAPSE_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
LayoutManager using getPreferredSize() when
calculating its layout (example VerticalLayout,
BorderLayout).
| Nested Class Summary | |
|---|---|
static interface |
JXCollapsiblePane.CollapsiblePaneContainer
Tagging interface for containers in a JXCollapsiblePane hierarchy who needs to be revalidated (invalidate/validate/repaint) when the pane is expanding or collapsing. |
static class |
JXCollapsiblePane.Direction
The direction defines how the collapsible pane will collapse. |
| 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.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
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 JXCollapsiblePane 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 JXCollapsiblePane is collapsed, i.e the icon which indicates the pane can be expanded. |
static String |
TOGGLE_ACTION
JXCollapsible 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 | |
|---|---|
JXCollapsiblePane()
Constructs a new JXCollapsiblePane with a JXPanel as content pane
and a vertical VerticalLayout with a gap of 2 pixels as layout
manager and a vertical orientation. |
|
JXCollapsiblePane(JXCollapsiblePane.Direction direction)
Constructs a new JXCollapsiblePane with a JXPanel as content pane and the specified
direction. |
|
JXCollapsiblePane(JXCollapsiblePane.Direction direction,
LayoutManager layout)
Constructs a new JXCollapsiblePane with a JPanel as content pane
and the given LayoutManager and orientation. |
|
JXCollapsiblePane(LayoutManager layout)
Constructs a new JXCollapsiblePane with a JPanel as content pane
and the given LayoutManager and a vertical orientation |
|
| Method Summary | |
|---|---|
protected void |
addImpl(Component comp,
Object constraints,
int index)
Overriden to redirect call to the content pane. |
Border |
getBorder()
Returns the border of this component or null if no
border is currently set. |
Container |
getContentPane()
|
JXCollapsiblePane.Direction |
getDirection()
|
Dimension |
getMinimumSize()
A collapsible pane always returns its preferred size for the minimum size to ensure that the collapsing happens correctly. |
Dimension |
getPreferredSize()
The critical part of the animation of this JXCollapsiblePane
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 |
setBorder(Border border)
Sets the border of this component. |
void |
setCollapsed(boolean val)
Expands or collapses this JXCollapsiblePane. |
void |
setContentPane(Container contentPanel)
Sets the content pane of this JXCollapsiblePane. |
void |
setDirection(JXCollapsiblePane.Direction direction)
Changes the direction of this collapsible pane. |
void |
setLayout(LayoutManager mgr)
Overriden to redirect call to the content pane. |
void |
setMinimumSize(Dimension minimumSize)
Forwards to the content pane. |
void |
setPreferredSize(Dimension preferredSize)
Sets the preferred size of this component. |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String ANIMATION_STATE_KEY
PropertyChangeEvent.getNewValue():
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
public static final String TOGGLE_ACTION
collapsiblePane.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION).
public static final String COLLAPSE_ICON
public static final String EXPAND_ICON
| Constructor Detail |
|---|
public JXCollapsiblePane()
JXPanel as content pane
and a vertical VerticalLayout with a gap of 2 pixels as layout
manager and a vertical orientation.
public JXCollapsiblePane(JXCollapsiblePane.Direction direction)
JXPanel as content pane and the specified
direction.
direction - the direction to collapse the containerpublic JXCollapsiblePane(LayoutManager layout)
JPanel as content pane
and the given LayoutManager and a vertical orientation
public JXCollapsiblePane(JXCollapsiblePane.Direction direction,
LayoutManager layout)
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
direction - the direction this pane collapseslayout - of this collapsible pane| Method Detail |
|---|
public void setContentPane(Container contentPanel)
contentPanel
should implement Scrollable and return true from
Scrollable.getScrollableTracksViewportHeight() and
Scrollable.getScrollableTracksViewportWidth(). If the content
pane fails to do so and a JScrollPane is added as a child, it is
likely that the scroll pane will never correctly size. While it is not
strictly necessary to implement Scrollable in this way, the
default content pane does so.
contentPanel - the container delegate used to hold all of the contents
for this collapsible pane
IllegalArgumentException - if contentPanel is nullpublic Container getContentPane()
public void setLayout(LayoutManager mgr)
setLayout in class Containermgr - the specified layout managerContainer.doLayout(),
Container.getLayout()
protected void addImpl(Component comp,
Object constraints,
int index)
addImpl in class Containercomp - the component to be addedconstraints - an object expressing layout constraints
for this componentindex - the position in the container's list at which to
insert the component, where -1
means append to the endContainer.add(Component),
Container.add(Component, int),
Container.add(Component, java.lang.Object),
LayoutManager,
LayoutManager2public void remove(Component comp)
remove in class Containercomp - the component to be removedContainer.add(java.awt.Component),
Container.remove(int)public void remove(int index)
remove in class Containerindex - the index of the component to be removedContainer.add(java.awt.Component)public void removeAll()
removeAll in class ContainerContainer.add(java.awt.Component),
Container.remove(int)public void setAnimated(boolean animated)
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.
animated - public boolean isAnimated()
setAnimated(boolean)public void setDirection(JXCollapsiblePane.Direction direction)
direction - the new JXCollapsiblePane.Direction for this collapsible pane
IllegalStateException - when this method is called while a
collapsing/restore operation is runninggetDirection()public JXCollapsiblePane.Direction getDirection()
JXCollapsiblePane.Direction.setDirection(Direction)public boolean isCollapsed()
public void setCollapsed(boolean val)
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 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 JXCollapsiblePane, such that the entire
JXCollapsiblePane will be invisible. If isAnimated() returns true,
the collapse will be accompanied by an animation.
isAnimated(),
setAnimated(boolean)public Border getBorder()
null if no
border is currently set.
getBorder in class JComponentJComponent.setBorder(javax.swing.border.Border)public void setBorder(Border border)
Border object is
responsible for defining the insets for the component
(overriding any insets set directly on the component) and
for optionally rendering any border decorations within the
bounds of those insets. Borders should be used (rather
than insets) for creating both decorative and non-decorative
(such as margins and padding) regions for a swing component.
Compound borders can be used to nest multiple borders within a
single component.
Although technically you can set the border on any object
that inherits from
This is a bound property.
JComponent, the look and
feel implementation of many standard Swing components
doesn't work well with user-set borders. In general,
when you want to set a border on a standard Swing
component other than JPanel or JLabel,
we recommend that you put the component in a JPanel
and set the border on the JPanel.
setBorder in class JComponent
border - the border to be rendered for this componentBorder,
CompoundBorder
public Dimension getMinimumSize()
To query the minimum size of the contents user getContentPane().getMinimumSize().
getMinimumSize in class JComponentJComponent.setMinimumSize(java.awt.Dimension),
ComponentUIpublic void setMinimumSize(Dimension minimumSize)
setMinimumSize in class JComponentminimumSize - the size to set on the content paneJComponent.getMinimumSize()public Dimension getPreferredSize()
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.
getPreferredSize in class JComponentJComponent.setPreferredSize(java.awt.Dimension),
ComponentUIpublic void setPreferredSize(Dimension preferredSize)
javax.swing.JComponentpreferredSize is null, the UI will
be asked for the preferred size.
setPreferredSize in class JComponentpreferredSize - The new preferred size, or nullComponent.getPreferredSize(),
Component.isPreferredSizeSet()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||