Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridBagConstraints weightx and weighty values

Tags:

java

swing

In many books weightx and weighty values are expressed in different ways:

some says 0.0 to 1.0 other says 0 to 100 other say until 1000

I'm a lot confused.

In the API these variables are double types so I think the first is correct but what does it meaning a value of 0.4 or 0.7? are percentage values, point values? relative of what?

like image 542
xdevel2000 Avatar asked Sep 15 '25 00:09

xdevel2000


2 Answers

I would follow the examples used in the Swing tutorial on How to Use GridBagLayout.

In that context 1.0 means as the frame grows the components gets all the extra space. 0.0 means it gets no space.

like image 106
camickr Avatar answered Sep 16 '25 14:09

camickr


Actually, these are weights. So what counts is that they are all on the same "scale".

It doesn't really matter then if percentage or not, in the end, they are evaluated regarding their total on a dimension. So just use what seems to be the most clear for you.

like image 28
Gnoupi Avatar answered Sep 16 '25 15:09

Gnoupi