Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

GridBagConstraints: weightx and weighty  RSS feed

 
Ramsin Khoshaba
Ranch Hand
Posts: 65
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I can't figure out what weightx and weighty do. I have looked at the API doc, but no luck.
Can you explain what they are for, reword the doc?

Thanks.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the tutorial on How to Use GridBagLayout will help. It explains all of the contraints and has working examples.
 
Stephan van Hulst
Saloon Keeper
Posts: 6966
109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a couple of components laid out in a panel, and you stretch the panel, the extra space needs to go somewhere. The weightx property determines how horizontal space is distributed over the cells, and weighty determines how vertical space is distributed.

If all cells have the same positive weight, the extra space is distributed evenly. If a cell has a weight that's twice as much as the weight of other cells, it will get two pixels of extra space for every pixel that the other cells get.

Let's say you have a label, a text area and a button, positioned vertically in that order. If you want the cell of the text area to soak up all the extra space if the container stretches, you can set the weighty of that cell to any positive value, and set the weighty of all the other cells to 0.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!