Date: Mon, 22 Oct 2001 15:47:45 -0400
To: [EMAIL PROTECTED]
From: Paul Brinkley <[EMAIL PROTECTED]>
Subject: Re: GridBagLayout disease
At 02:29 PM 10/22/2001 -0400, [EMAIL PROTECTED] wrote:
>I have a GUI consisting of three areas:
>
> ___ ___
> | | B |
> | A |---|
> | | C |
> |___|___|
>
>* Area A contains a JTree inside a JScrollPane.
>
>* Area B contains a JTextField, a JButton, and 3 JRadioButtons.
>
>* Area C contains a JSplitPane, which in turn contains a JList within
> a JScrollPane in the top pane, and a JTree within a JScrollPane in
> the bottom pane.
>[snip]
First, in GBLs, the weight constraints govern how to allocate a -change- in
dimension, as opposed to total dimension.
Thanks, that was useful.
I wrote a small class that shows some of the pathologic behavior I'm
getting (see source code below). Running it produces a GUI of the
form:
___ ___
| | |
| A | B |
| | |
|___|___|
To see the problem, just shorten the window *vertically* (keeping the
width constant). Even a slight shortening will do. The result will
look like
__ ____
| | |
|A | B |
|__|____|
i.e., vertically shorter, but A is narrower, and B wider, than before,
even though there was no horizontal resizing at all.
This sure looks like a bug to me. Is there a way around it?
KJ
/* Class: Sick */
import javax.swing.*;
import java.awt.*;
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;
tree = new JTree();
scrollPane = new JScrollPane(tree);
gbc = getBaseConstraints();
gbc.gridx = 0;
add(scrollPane, gbc);
panel = new JPanel();
button = new JButton("button");
panel.add(button);
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