-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
1.2.2
-
x86
-
windows_nt
Name: dbT83986 Date: 12/23/98
The error causes a JSplitPane's left pane and divider
to completely disappear if the JSplitPane is:
- part of a CardLayout
- not the first card
- within a panel with an inset border
To reproduce, run the following program and click the
"Show SplitPane" button.
--------------------------------
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import com.sun.java.swing.tree.*;
public class CardSplitTest extends JFrame
{
JPanel mainPanel;
CardLayout cardLayout;
public CardSplitTest(boolean showSplitFirst) {
mainPanel = new JPanel(cardLayout = new CardLayout());
JSplitPane splitPane = new JSplitPane();
JPanel splitContainer = new JPanel(new BorderLayout());
splitContainer.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
splitContainer.add(splitPane, BorderLayout.CENTER);
if (showSplitFirst) {
mainPanel.add(splitContainer, "split");
mainPanel.add(new JPanel(), "blank");
}
else {
mainPanel.add(new JPanel(), "blank");
mainPanel.add(splitContainer, "split");
}
getContentPane().add(mainPanel, BorderLayout.CENTER);
JButton button = new JButton("Show JSplitPane");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cardLayout.show(mainPanel, "split");
}
});
getContentPane().add(button, BorderLayout.SOUTH);
}
public static void main (String[] args) {
JFrame f = new CardSplitTest(args.length > 0);
f.pack();
f.show();
}
}
--------------------------------
The problem stems from the fact that CardLayouts only
set the bounds of their initial child component, but cause
doLayout() to be invoked on all children. This causes
children to lay themselves out with respect to a
bounding rect of (0,0,0,0); if nested panels have
inset borders, then bounds of children can go
negative. A JSplitPane "remembers" the initial size
of its left panel as a negative size, causing the
left panel to disappear.
Other components besides JSplitPane can be affected
by this scenario, but I have not thoroughly tested
them all. Perhaps CardLayout's behavior is the
one that should change, rather than JSplitPane...
(Review ID: 38781)
======================================================================