Skip to main content

How to make JXCollapsiblePane scrollable?

2 replies [Last post]
sbozian
Offline
Joined: 2010-08-30
Points: 0

According to the documentation of JXCollapsiblePane.setContentPane(Container contentPanel), the default content pane implements Scrollable and returns true from Scrollable.getScrollableTracksViewportHeight() and Scrollable.getScrollableTracksViewportWidth().

Indeed, the default content pane is of type JXPanel which satisfies the above requirements. Yet, the collapsible pane is not scrollable.

To reproduce the problem, run the example below and try to minimize the window size. The scroll bars do not appear, and the content pane is not scrollable.

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.border.TitledBorder;

import org.jdesktop.swingx.JXCollapsiblePane;
import org.jdesktop.swingx.JXFrame;

public class APIexample {

public static void main(String[] args) {
JXCollapsiblePane cp = new JXCollapsiblePane();

cp.getContentPane().setLayout(new GridLayout(6, 2));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));
cp.getContentPane().add(new JButton("Collapsible"));

JXFrame frame = new JXFrame();
frame.setLayout(new BorderLayout());
frame.add("North", cp);
frame.add("South", new JButton(cp.getActionMap().get("toggle")));
frame.pack();
frame.setVisible(true);
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

There is no JScrollPane in this example. Perhaps you should review what the Scrollable interface is.

Karl

sbozian
Offline
Joined: 2010-08-30
Points: 0

Indeed, I had a misconception of the Scrollable interface.

Thank you.