Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JRadioButton : Deselecting

 
Vikram Deshmukh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Group,
I have a button group. Within that, I am having 2 JRadioButtons. One of them is selected. On click of some JButton, i want to de-select that radio button.
On handler of JButton i wrote, but it doesnt work.
Does anyone has any remedy over this ?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At least one button in a ButtonGroup must be selected. If you read the API for ButtonGroup it gives you this workaround...


Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in the group. There is no way to turn a button programmatically to "off", in order to clear the button group. To give the appearance of "none selected", add an invisible radio button to the group and then programmatically select that button to turn off all the displayed radio buttons. For example, a normal button with the label "none" could be wired to select the invisible radio button.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wouldn't it be possible to add the "some JButton" to the button group?
cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic