This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic