File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enabling/Disabling a radiobutton based on response of another radiobutton

 
Anthony Donovan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47292
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic