I am dinamically generating a layout which requires to use relative sizes, the only way I found to do it without using an external Java layout library is GridBagLayout's weightx and weighty.
At this point it has been working exactly as I need with one small exception. When I have one column containing two JPanels with a space distribution of 66.6% and 33.3% respectively and then another column with 3 JPanels using 33.3% of the space each one of them, the 33.3% of the first column is not the same as the 33.3% of the second. I need them to be perfectly aligned.
Unfortunately this is my first post and I am not able to post any pictures, I hope I won't get in trouble for doing the following:
I think I know what the problem is, inside of each JPanel I have one JLabel and since weightx and weighty's definition is "Weights are used to determine how to distribute space among columns (weightx) and among rows (weighty)" I guess the difference between the two 33.3%s is the fact that the second column contains one extra JLabel.
In this thread StanislavL says that the "container asks children for their preferred size", so, I am wondering if the solution is to override JLabel's getPreferredSize method. I am not sure how "dirty" would be to do that, I would appreciate a lot your suggestions to solve this problem.
Thanks in advance!
Diego