Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JRadio Btn

 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have any idea how to clear a radio button after it has been selected. A user selects a radio btn but then clears it after hitting another btn. All radio btns are in a btn group. How to clear it?

Tks
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you add the buttons to a ButtonGroup and enable one, the clicked buton will be enabled and the others will be disabled automatically.
 
GD Deepz
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply but I think was misinterperted. I already added radio btns to a group and they are mutually exlusive. Consider the following:

1. User selects a radio btn
2. User then clicks on a "Clear" JButton, all radio btns should be cleared ---> meaning all the radio btns should be deselected, none of the radio btns should selected.

When the frame first starts up, none of the radio btns are selected until a user selecte one, this is the effect I want to achieve i.e the initial startup.

I have tried the setSelected(false) method for each radio btn it does not work.
 
Michael Imhof
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using JCheckbox instead of JRadiobutton.
That should solve your problem because radiobuttons are per definition exclusive.

Greez
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by GD Deepz:
Does anybody have any idea how to clear a radio button after it has been selected. A user selects a radio btn but then clears it after hitting another btn. All radio btns are in a btn group. How to clear it?

Tks


The API docs state that there is no way to do this. JRadioButtons start out all unselected, but always show one selected button after that. The docs suggest using an invisible button to achieve this. Here's a working example.
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest an alternative, namely that you cater for the fact that one *has* to be selected. You could have a checkbox that disables the whole button group or another visual radio button for "none". This will fit in with both the programmatic model and the learned behaviour of radio buttons by your users.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Nagappan:
I'd suggest an alternative, namely that you cater for the fact that one *has* to be selected. You could have a checkbox that disables the whole button group or another visual radio button for "none". This will fit in with both the programmatic model and the learned behaviour of radio buttons by your users.


I once had a '66 buick that had a radio with real radio buttons. It was possible to deselect all of them by pressing one button half way in. This behaviour isn't possible on my current tuner. I agree that a "none" button is probably more intuitive to modern users. To get that effect just add the zero button rb0 to the pane as well as to the button group in the example I posted.

I'm not sure just where these are needed in the scjd assignments, but the code I posted does what the OP wants in the manner recommended by the API reference.
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by peter wooster:
It was possible to deselect all of them by pressing one button half way in. This behaviour isn't possible on my current tuner.


Agreed, I remember those old tuners

IMHO it takes the same screen real estate to post a "none" radio button as it does to post a "clear" button, but the user interface is much cleaner.

I also don't know why you'd need it for the assignment...
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Nagappan:

Agreed, I remember those old tuners

IMHO it takes the same screen real estate to post a "none" radio button as it does to post a "clear" button, but the user interface is much cleaner.

I also don't know why you'd need it for the assignment...


I agree, just give them a "none of the above" button. If they never had a '66 Buick they won't know what they're missing.
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for the reply but I think was misinterperted. I already added radio btns to a group and they are mutually exlusive. Consider the following:

1. User selects a radio btn
2. User then clicks on a "Clear" JButton, all radio btns should be cleared ---> meaning all the radio btns should be deselected, none of the radio btns should selected.

When the frame first starts up, none of the radio btns are selected until a user selecte one, this is the effect I want to achieve i.e the initial startup.

I have tried the setSelected(false) method for each radio btn it does not work.



Have a hidden check button, that you can make 'checked' in the background on click.
[ November 09, 2004: Message edited by: James Clinton ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic