Skip to content
Advertisement

GridBagLayout Adding Space between buttons/stagger/varied columns?

I am trying to create a layout with GridBagLayout but am having trouble getting the spaces in between the JButton controls to be equal. In the first row, there are 5 buttons that have no space in between. The second and third row should have 4 buttons which are smaller which spaces in between.

The workaround I tried was to make it a 35×35 grid where the top buttons have width 7 and the other buttons width 5. I cannot figure out how to get the 4 buttons to align evenly (The space in the last column is smaller).

enter image description here

Code below:

JavaScript

Advertisement

Answer

I’d approach this GUI as one border layout containing two grid layouts.

enter image description here

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