Search code examples
javaswinglayoutlayout-managersizing

Java Swing Controls: very small when minimized?


I have a Swing JFrame with some controls in a GridLayout.

My problem is that the controls (Text fields) appear too small when the frame is minimized. I tried to avoid this by setting:

setPreferredSize

and

setSize

but still, I have to maximize the frame to see the controls clearly.

How can I solve this ?

Thanks enter image description here


Solution

  • No code is posted, but it is possible that you're not constructing the textfields with specified number of columns. setPreferredSize or setSize are not needed, try this instead:

    JTextField tf = new JTextField(30)
    

    which will create a textfield of fixed size (columns) 30. This way your textfields will not shrink or expand.