Skip to content
Advertisement

Java Swing JButton alignment – BoxLayout

Below is a small example where two radio buttons are offset too far to the left column.

Radiobutton labels are incorrectly offset

However, if I remove the “A” button above by commenting out this code:

enter image description here

Then the 2 radio buttons are displayed as expected and not offset:

enter image description here

How do I get the radio buttons aligned correctly like the second case, but with the button present? Here is the code:

Main.java:

JavaScript

LeftPanel.java:

JavaScript

ButtonPanel.java:

JavaScript

Advertisement

Answer

It could be to do with the “alignmentX” property for those items. Trying setting all those items to the same alignmentX value.

enter image description here

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