I would like to create a layout: 2 rows, 1 column. 1st row should occupy 70% height of the window and 2nd row 30% of the window. I achieve this by using weighty
attribute of GridBagConstraints
.
However I have problem with the width of my component, because when I resize application window the component remain in the center, its width is constant and I get a white spaces in the left and right of the component (even if I set fill
to BOTH
). This problem does not occur when I change the height of the window (components resize very well and fill full height of the window).
Below my constraints:
firstConstraints.gridx = 0;
firstConstraints.gridy = 0;
firstConstraints.weighty = 0.7;
firstConstraints.fill = GridBagConstraints.BOTH;
secondConstraints.gridx = 0;
secondConstraints.gridy = 1;
secondConstraints.weighty = 0.3;
secondConstraints.fill = GridBagConstraints.BOTH;
simple example
I think you also need:
See the secton from the Swing tutorial on How to Use a GrigBagLayout that talks about the weightx, weighty constraints.