How to null out-reset JRadioButtons!

I have a Java swing application and I can't seem to null out the radio buttons (JRadioButtons) after it performs a reset - the syntax for this section is the following where years, monthly and amount are my JButtonGroups! The actually radiobuttons are called rad1, rad2, rad3, rad4, rad4, rad6, rad7, rad8, rad9 as each buttongroup has three radio buttons assigned to it

if(source == button2){
total = 0; //clear total or else the value will stay for next calculation
//set radio buttons to unchecked also
years = 0;
monthly = 0;
amount = 0;

                        textLabel5.setText("");
                  }
LVL 1
kpu8Asked:
Who is Participating?
 
objectsCommented:
>  I'm a little unclear how to make a button invisible!

just don't add it to your container

JRadioButton a = new JRadioButton("a");
panel.add(a);
group.add(a);
JRadioButton b = new JRadioButton("b");
panel.add(a);
group.add(a);
JRadioButton deselect = new JRadioButton("");
group.add(deselect );


then to deselect all use:

deselect.setSelected(true);
0
 
CEHJCommented:
Which ones do you need to deselect (there has to be one in each group selected)
0
 
objectsCommented:
add an extra radio button to the group and make it invisible.
to reset, select that radio button.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
objectsCommented:
to make it invisible simply don't add it to your container (but do add it to your button group)
0
 
kpu8Author Commented:
CEHJ - The request was to make them all deselected!

objects - Any examples would be great of how to do this - I'm a little unclear how to make a button invisible!
0
 
CEHJCommented:
>>CEHJ - The request was to make them all deselected!

Well that's not how radio buttons are meant to work - checkboxes yes, radio buttons no ;-)
0
 
objectsCommented:
The code I posted demonstrates how to null out a group of radio buttons as asked.
And is the accepted way to achieve what is required.
0
 
CEHJCommented:
And i was just pointing out that kpu8 should know that's not how radio buttons are meant to work and that making them work like that is simply bad gui design
0
 
objectsCommented:
Have a set of radio buttons with none selected is a perfectly valid state.
The question doesn't ask how radio buttons are meant to work, it ask how to reset them which I have answered.
0
 
CEHJCommented:
>>Have a set of radio buttons with none selected is a perfectly valid state.

No - it is not
0
 
objectsCommented:
When you first create an rb it is unselected, ie. its a valid state.
0
 
CEHJCommented:
That's a different issue. A single radio button is in any case a theoretical entity in a gui
0
 
objectsCommented:
Why would I be talking about a single radio button :-D
0
 
CEHJCommented:
I don't know but you were unless 'an rb' is plural in your world ..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.