简体   繁体   中英

Centering Radio Buttons in a GridLayout

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?

您可以使用:

radioButton.setHorizontalAlignment(SwingConstants.CENTER);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM