Search code examples
javaswingjbuttonjradiobutton

JradioButton that is in ButtonGroup to setSelected


I have two JRadioButtons: SabiranjeradioButton (which I put in ButtonGroup) and Dijeljenjerdbtn (which I did NOT put in a ButtonGroup). I want to make a Reset Button so when I click the button the program should be as it opened.

The problem is that I tried to use the method .setSelected(false) to remove the select from the JRadioButtons but it does not work for the SabiranjeradioButton (which I put in ButtonGroup).

Can anyone help me?


Solution

  • A ButtonGroup does not let all of the RadioButtons to be unselected at the same time. You can clear the selection manually via the ButtonGroup#clearSelection method.

    Clears the selection such that none of the buttons in the ButtonGroup are selected.