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 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"));
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.In this example, the
JXCollapsiblePaneis used to build a Search pane which can be shown and hidden on demand.The
JXCollapsiblePanehas 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. ExampleNote:
JXCollapsiblePanerequires its parent container to have a LayoutManager using getPreferredSize() when calculating its layout (example VerticalLayout , BorderLayout ).