et the font collapsiblePane.getContentPane().setFont(font); // to set the background color collapsiblePane.getContentPane().setBackground(Color.RED); For convenience, the {@code add} and {@code remove} methods forward to thecontent 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 {@code add}, use {@link #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 {@link #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 {@link #EXPAND_ICON} and {@link #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 {@link java.awt.LayoutManager} using {@link #getPreferredSize()} whencalculating its layout (example {@link org.jdesktop.swingx.VerticalLayout}, {@link java.awt.BorderLayout}).
@javabean.attribute name="isContainer" value="Boolean.TRUE" rtexpr="true"
@javabean.attribute name="containerDelegate" value="getContentPane"
@javabean.class name="JXCollapsiblePane" shortDescription="A pane which hides its content with an animation." stopClass="java.awt.Component"
@author rbair (from the JDNC project)
@author Frederic Lavigne
@author Karl George Schaefer