May 19

When you add a JTextField to a BoxLayout managed panel it will expand vertically to take up available space.

To avoid this you can simply set the maximum size of the field to be the same as its preferred size.

textField.setMaximumSize( textField.getPreferredSize() );

written by objects \\ tags: , ,

Array ( ) 2 Responses to “Stop JTextField from expanding in BoxLayout”

  1. Programmer Says:

    Thanks a lot.

  2. Jim Says:

    Thanks 🙂

Leave a Reply

You must be logged in to post a comment.