Home arrow static arrow Java Programming [Archive] - GridBagLayout question....
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - GridBagLayout question....
This topic has 1 reply on 1 page.

Posts:85
Registered: 4/23/03
GridBagLayout question....  
Jun 15, 2004 12:52 PM



 
Hi,

I'm working in a swing aplication that uses GridBagLayout in its panels. The problem I've with this layout manager is when I add a panel with GridBagLayout to a JFrame and this JFrame is resized the components in the panel don't resize.

for example, look the following code:

JPanel master = new JPanel();master.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints();c.fill = GridBagConstraints.BOTH; JPanel panel1 = new JPanel(new GridLayout(3,4));panel1.add(new JLabel()); c.gridx = 0;c.gridy = 0;c.weightx = 0.0;c.weighty = 0.0;master.add(panel1,c); JPanel panel2 = new JPanel(new GridLayout(3,4));panel2.add(new JTree()); c.gridx = 0;c.gridy = 1;c.weightx = 0.0;c.weighty = 0.0;master.add(panel2,c);


I've a panel called "master" with GridBagLayout this panel has two components added, "panel1" and "panel2".

When the container component in which "master" panel is added (a JFrame) is resized the "master" panel changes its size according container size too, but "panel1" and "panel2" don't changes its size and the layout manager fits them in the center of "master" panel.

What I can do for components added to a panel with GridBagLayout can resize according parents components size ?

thanks in advance
 

Posts:2,384
Registered: 3/16/01
Re: GridBagLayout question....  
Jun 15, 2004 1:32 PM (reply 1 of 1)



 
The fill constraint will not cause components to expand unless weightx and/or weighty are non–zero.
 
This topic has 1 reply on 1 page.