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() );
2 Responses to “Stop JTextField from expanding in BoxLayout”
Leave a Reply
You must be logged in to post a comment.