1

Good afternoon!

I have this two methods that create 5 rows with each row being a label and five radio buttons on a button group:

private JPanel criarPainelAvaliacoes() {
    JPanel painel = new JPanel();
    BoxLayout box = new BoxLayout(painel, BoxLayout.Y_AXIS);
    painel.setLayout(box);

    painel.add(criarPainelAvaliacoes("text1"));
    painel.add(criarPainelAvaliacoes("text2"));
    painel.add(criarPainelAvaliacoes("text3"));
    painel.add(criarPainelAvaliacoes("text4"));
    painel.add(criarPainelAvaliacoes("text5"));

    return painel;
}


private JPanel criarPainelAvaliacoes(String texto) {
    JPanel avaliacoes = new JPanel();
    avaliacoes.setLayout(new FlowLayout());
    ButtonGroup btg1 = new ButtonGroup();
    JRadioButton rd0 = new JRadioButton("0");
    JRadioButton rd1 = new JRadioButton("1");
    JRadioButton rd2 = new JRadioButton("2");
    JRadioButton rd3 = new JRadioButton("3");
    JRadioButton rd4 = new JRadioButton("4");
    JRadioButton rd5 = new JRadioButton("5");
    btg1.add(rd0);
    btg1.add(rd1);
    btg1.add(rd2);
    btg1.add(rd3);
    btg1.add(rd4);
    btg1.add(rd5);

    avaliacoes.add(new JLabel(texto));

    avaliacoes.add(rd0);
    avaliacoes.add(rd1);
    avaliacoes.add(rd2);
    avaliacoes.add(rd3);
    avaliacoes.add(rd4);
    avaliacoes.add(rd5);

    return avaliacoes;
}

My problem is that this way the RadioButtons dont align properly. How can I do so that they align horizontally? I've tried using gridbag too together with constraints.gridx and gridy but no sucess.

Thanks in advance

Diogo Santos
  • 780
  • 4
  • 17

0 Answers0