Question

I have 3 JPanel, the first is the base panel and the other two are added to the first. I have realised that there is a lot of space that is not used, shown by the black color and the white color around components.

How do you remove this space?

alt text

Was it helpful?

Solution

If you are using either GridLayout or BorderLayout they both have methods to change the space between components.

In GridLayout this can be done in the 4 int parameter consturctor and in BorderLayout the 2 int parameter constructor. Both LayoutManagers have the methods setHgap and setVgap.

If you are using GridBagLayout you need to make sure that the insets on the GridBagConstraints is changed to whatever you need. Guessing you are using one of the other managers though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top