Issue
i'm trying to make a UI panel that serves like a form (Im not using GUI designer). Left side contains labels, and the right side contains text field, etc. I want to make it, so that when resized, only the right size (the text fields, change shape).
Currently, i am using GridLayout(x, 2)
with one JLabel
and JTextField
per row.
So on resize, i wanna make it so that this goes
from [(JLabel)|(JTextField)]
to [(JLabel)|( JTextField )]
not [( JLabel )|( JTextField )]
.
Plus, of course, i need to make sure that all of the rows always match.
Solution
If you want to use a single layout manager you could use a GridBagLayout
.
For the components in the second column you would set the weightx
constraint to 1.0f. This means any extra space will only be allocated to this component.
Read the section from the Swing tutorial on How to Use GridBagLayout. The topic on Specifying Constraints
will explain in more detail how this constraint works.
Answered By - camickr
Answer Checked By - Marie Seifert (JavaFixing Admin)