0

I created several radio buttons in a button group but I cannot understand how to set necessary radio button in a code. My program reads the personal information in a file and shows it in the form (one person at a time). The personal information includes a marital status apart from name and other data, so I use radio buttons for the marital status.

This is my code (I used class Person with public enum MaritalStatus {SINGLE, MARRIED, WIDOW};):

buttonGroup = new ButtonGroup();
            for (Person.MaritalStatus c : Person.MaritalStatus.values()) {
                    JRadioButton radioButton = new JRadioButton(c.name());
                    buttonGroup.add(radioButton);
        if (c == mStatus) {
                        radioButton.setSelected(true);
                    }
        radioButtonPanel.add(radioButton);
            }

So, I have a group of radio buttons:

SINGLE, MARRIED, WIDOW

If user changes the person, the program must update the info about the marital status of the next person in a file. In other words, I don't know how to choose necessary radio button. The method of button group setSelected(buttonModel, bool) requires the buttonModel/radioButton name, but I don't have it in the code

Michał
  • 2,456
  • 4
  • 26
  • 33

0 Answers0