• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GridBagLayout problems

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cool, thanks a lot! I'll try it using the REMAINDER
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic