Enabling/Disabling a radiobutton based on response of another radiobutton
Anthony Donovan
Greenhorn
Joined: Oct 20, 2010
Posts: 2
posted
0
I have a group of jradiobuttons and two subgroups under it. I want the two subgroups to be disabled unless one of the options is selected. How would I go about doing this? Also I'm using netbeans.
What have you tried so far? And why didn't that work? If you have no clue add all look at the javax.swing.JRadioButton (including the inherited methods).
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32604
4
posted
0
Moving to our GUIs forum, where we usually discuss such questions.
As Wouter has said, you need to add the radio buttons to a group; there is a class called ButtonGroup or similar which you add them to. If one button in that group is activated, the others are all immediately de-activated. There is something in the Java™ Tutorials which I think will help you
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32604
4
posted
0
Actually, seeing you want subgroups, maybe my suggestion won't be as helpful as I thought. Sorry. But I shall still move this thread.
ButtonGroup is notoriously awkward to work with for this kind of customization, but you could add listeners to the two radio buttons of interest and query their selected states to decide whether to enable/disable the buttons of the subgroup, which IMO should be in an array (or even two arrays) for ease of addressing.
luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
add an actionListener to each of the 'group of jradiobuttons' to enable the (array) of subgroup radiobuttons
override the 'group of jradiobuttons' ButtonGroup's clearSelection() to disable the (array) of subgroup radiobuttons
Anthony Donovan
Greenhorn
Joined: Oct 20, 2010
Posts: 2
posted
0
Michael Dunn wrote:add an actionListener to each of the 'group of jradiobuttons' to enable the (array) of subgroup radiobuttons
override the 'group of jradiobuttons' ButtonGroup's clearSelection() to disable the (array) of subgroup radiobuttons
thanks it worked
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Enabling/Disabling a radiobutton based on response of another radiobutton