sharing everything

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 :

My name is Toto Sugito. This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.

No Comments Yet

Leave a Reply

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



Bloggers - Meet Millions of Bloggers