Have you set the preferred size on the components you are adding?
For example, if you are adding two JPanel's to the container you need to set
the preferred size on the JPanel's.
This has no effect on the observed behavior, as shown by compiling and
running the updated class definition below. The preferred sizes are:
tree: java.awt.Dimension[width=83,height=72]
scrollPane: java.awt.Dimension[width=86,height=363]
button: java.awt.Dimension[width=71,height=29]
panel: java.awt.Dimension[width=81,height=39]
KJ
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Sick extends JPanel {
private static JFrame frame;
private JScrollPane scrollPane;
private JPanel panel;
private JTree tree;
private JButton button;
public Sick() {
super();
setLayout(new GridBagLayout());
GridBagConstraints gbc;
Dimension size;
tree = new JTree();
size = tree.getPreferredSize();
System.out.println("tree: " + size);
tree.setPreferredSize(size);
scrollPane = new JScrollPane(tree);
size = scrollPane.getPreferredSize();
System.out.println("scrollPane: " + size);
scrollPane.setPreferredSize(size);
gbc = getBaseConstraints();
gbc.gridx = 0;
add(scrollPane, gbc);
button = new JButton("button");
size = button.getPreferredSize();
System.out.println("button: " + size);
button.setPreferredSize(size);
panel = new JPanel();
panel.add(button);
size = panel.getPreferredSize();
System.out.println("panel: " + size);
panel.setPreferredSize(size);
gbc = getBaseConstraints();
gbc.gridx = 1;
add(panel, gbc);
}
private GridBagConstraints getBaseConstraints() {
GridBagConstraints baseGbc = new GridBagConstraints();
baseGbc.weightx = baseGbc.weighty = 1.;
baseGbc.fill = GridBagConstraints.BOTH;
baseGbc.gridy = 0;
return baseGbc;
}
public static void main(String[] args) {
frame = new JFrame();
frame.getContentPane().add(new Sick(), "Center");
frame.pack();
frame.show();
}
}
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing