Java Prevent BoxLayout From Expanding Children

I have created design GUI using java by programmatically. I want to add some of JPanel to my JFrame (mainwindow). I set JFrame layout using BoxLayout. I am use BoxLayout because want the children resize only width. But, when I resize the mainwindow (JFrame), children width and height is resized. BoxLayout expanding all children width and height.

This is code to add JPanel to my JFrame using BoxLayout :

Output using this code is like this :

java_jframe_resized_01Alternatively, we can use Box.Filler prevent BoxLayout resized the childen height. I have modified my code like this :

The result using this modified code (prevent BoxLayout expanding all children) is like this :

java_jframe_resized_02Add Box.Filler to our BoxLayout prevent all children expanding they height.

Source :

Add a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.