Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GridBagLayout problems

 
Alex Chopping
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool, thanks a lot! I'll try it using the REMAINDER
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic