aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Enabling/Disabling a radiobutton based on response of another radiobutton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Enabling/Disabling a radiobutton based on response of another radiobutton" Watch "Enabling/Disabling a radiobutton based on response of another radiobutton" New topic
Author

Enabling/Disabling a radiobutton based on response of another radiobutton

Anthony Donovan
Greenhorn

Joined: Oct 20, 2010
Posts: 2
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.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Hi Anthony and welcome to the JavaRanch.

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: 38768
    
  23
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: 38768
    
  23
Actually, seeing you want subgroups, maybe my suggestion won't be as helpful as I thought. Sorry. But I shall still move this thread.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4541
    
    5

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.

Or you could use my Select Button Groupand add a PropertyChangeListener coded to your requirement.


luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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
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://aspose.com/file-tools
 
subject: Enabling/Disabling a radiobutton based on response of another radiobutton