I am curious if it possible to center a JButton in two X grids of a GridBagLayout? I've done some searching through the API but haven't found much. I have also drawn up a small picture to clarify what I am trying to do.
Thank you!
Example Image:
I've done some searching through the API but haven't found much.
Read the section from the Swing tutorial on How to Use GridBagLayout.
You would need to concentrate on the Specifying Constraints
section:
gridwidth
constraint will allow the button to span multiple columnsanchor
constraint will allow the button to be centered within the two columns.fill
constraint will need to be turned off.The above assumes that you actually have other components on the panel in each of the columns. You can't just randomly say a single component takes up two columns.
So start with the demo code in the tutorial an modify it to have the button on the bottom centered.