aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout problems" Watch "GridBagLayout problems" New topic
Author

GridBagLayout problems

Alex Chopping
Greenhorn

Joined: Apr 23, 2003
Posts: 5
Was wondering if someone could tell me what I'm doing wrong here - I'm trying to set the following out in a JPanel with a gridBagLayout, and everything has gone in its right place except for label_14, which instead of going below label_11, has been put on the top right of row 1 in a new column by itself. (All the labels are JLabels)
*************************************************
GridBagConstraints c = new GridBagConstraints();
GridBagLayout layout = new GridBagLayout();
// In the constructor:
this.setLayout(layout);
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridheight = 8;
c.fill = GridBagConstraints.BOTH;
add(label_1, c);

c.gridx = 1;
c.gridwidth = 2;
c.gridheight = 1;
add(label_2, c);

c.gridy = 2;
add(label_3, c);

c.gridy = 4;
add(label_4, c);

c.gridy = 6;
add(label_5, c);

c.gridx = 3;
c.gridy = 0;
c.gridwidth = 1;
c.gridheight = 8;
add(label_6, c);

c.gridx = 1;
c.gridy = 1;
c.gridheight = 1;
add(label_7, c);

c.gridy = 3;
add(label_8, c);

c.gridy = 5;
add(label_9, c);

c.gridy = 7;
add(label_10, c);

c.gridx = 2;
c.gridy = 1;
add(label_11, c);

c.gridy = 3;
add(label_12, c);

c.gridy = 5;
add(label_13, c);

c.gridy = 7;
add(label_14, c);
*************************************************
Can anyone tell me what I'm doing wrong, it would be much appreciated!
Thanks!
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
This is why I prefer to not place them using x/y. Here is an example of just placing them left to right and using the remainder.
Example.
I will look at yours further later and see what I can.
Alex Chopping
Greenhorn

Joined: Apr 23, 2003
Posts: 5
cool, thanks a lot! I'll try it using the REMAINDER
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout problems