The Source for Java Technology Collaboration


Home | Changes | Index | Search | Go

Extending the SwingX JXCollapsiblePane

SwingX comes with the JXTaskPane component which mimics the Microsoft Windows Explorer "Tasks" component. The JXTaskPane component gets its animation and content pane hiding capability from the JXCollapsiblePane.

If you look at the JXCollapsiblePane JavaDoc, you'll find how you can use the JXCollapsiblePane to hide some components until they are needed by the end-user - such as hiding the Search bar until the keyboard shortcut "ctrl + F" is invoked. JXCollapsiblePane comes handy when you are in need of screen real-estate.

Let's look at the Netbeans Profiler and its user interface. Specially look at this screenshot, notice the left panel with the "Controls", "Status", "Profiling Results" panels stacked together. Each panel can be collapsed by clicking on the same arrow widget.

The good news is SwingX gives you everything you need to replicate this user interface. By assembling JXHyperlink and JXCollapsiblePane you can easily implement a similar component. That's what I did and here comes the StackedBox:

PICK Try it Java WebStart Demo of the StackedBox

All Boxes Expanded All Boxes Collapsed

Using the StackedBox? is easy:

// create a frame
JFrame frame = new JFrame("Example");
frame.setSize(200, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// create the stackedbox
StackedBox box = new StackedBox();
// put it in a scrollpane
JScrollPane scrollPane = new JScrollPane(box);
scrollPane.setBorder(null);
frame.add(scrollPane, BorderLayout.CENTER);

Component controls = makeControlPanel();
// add a component to the box with the title "Controls"
box.addBox("Controls", controls);

frame.setVisible(true);

If you want to use the StackedBox in your code, get StackedBox.java

The example previously depicted can be found in CollapsibleAtWork.java.

-- Main.l2fprod - 20 Nov 2005

Topic SwingLabsSwingXJXCollapsiblePaneExtending . { Edit | Ref-By | Printable | Diffs r6 < r5 < r4 < r3 < r2 | More }
 XML java.net RSS

Revision r6 - 27 Jul 2009 - 20:01:44 - Main.nsushkinofc