Reputation: 956
I am trying to create an application using GridLayout and I don't know how to center some radio buttons. The window ends up looking like:
Here is how I added the radio buttons:
JPanel qArea = new JPanel(new GridLayout(0,5));
...
qArea.add(new JPanel());
qArea.add(o1);
qArea.add(o2);
qArea.add(o3);
qArea.add(o4);
while(i<50)
{
if (i%5 == 0)
qArea.add(qs[cq++]);
else
qArea.add(buttons[crb++]);
i++;
}
Is there any way I can center the radio buttons inside their columns?
Upvotes: 4
Views: 3210
Reputation: 159804
You can use:
radioButton.setHorizontalAlignment(SwingConstants.CENTER);
Upvotes: 8