• Post Reply Bookmark Topic Watch Topic
  • New Topic

Radio Button  RSS feed

 
Ahmed Barradah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning all,
I am trying to design a GUI for radio buttons where 0 or 1 radio button is selected instead of having at least one radio button is selected. I konw that once you select a radio button then there always must be one radio button selected, but I want to overide that, do you know a way around this? Thanks for yout time!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create an additional radio button, add it to the buttonGroup, but not to the gui.
then, when you want no-selection showing, select the hidden button
 
Ahmed Barradah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please show me an example, I am kinda new to designing GUIs in Java
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's just a matter of adding an extra radio button on to your existing code.
if your current code has rb0, and rb1, create rb2
JRadioButton rb2 = new JRadioButton();
buttonGroup.add(rb2);
no more required (allow for scope of rb2)

now, whenever you want your screen to show no-selection between rb0 and rb1,
rb2.setSelected(true);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!