Skip to content
Advertisement

How to make Java Swing components fill available space?

I cannot seem to get my Java Swing components to work together correctly.

What I want to do, is have a JPanel fill ALL the space available inside a JTabbedPane. At the moment, my setup is as follows:

JavaScript

This creates a windows that is my desired size (dynamically proportional to the screen size, not included in above code). The tab panel that is placed in the center is expanded to fill all the space required, which is exactly what I want. But, the panels I add inside the tab panel are only as big as their content. If I add labels or anything, it only grows as big as the components. I want them to always be expanded to fill the tab panel.

Advertisement

Answer

Try setting the weights of the GridBagConstraints to non-zero values:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement