Solved

How to null out-reset JRadioButtons!

Posted on 2004-10-02
15
541 Views
Last Modified: 2010-03-31
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("");
                  }
0
Comment
Question by:kpu8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12209255
Which ones do you need to deselect (there has to be one in each group selected)
0
 
LVL 92

Expert Comment

by:objects
ID: 12209277
add an extra radio button to the group and make it invisible.
to reset, select that radio button.
0
 
LVL 92

Expert Comment

by:objects
ID: 12209862
to make it invisible simply don't add it to your container (but do add it to your button group)
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:kpu8
ID: 12212314
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12213038
>>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
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 12213898
>  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
 
LVL 92

Expert Comment

by:objects
ID: 12449621
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12449690
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
 
LVL 92

Expert Comment

by:objects
ID: 12449697
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12449714
>>Have a set of radio buttons with none selected is a perfectly valid state.

No - it is not
0
 
LVL 92

Expert Comment

by:objects
ID: 12449731
When you first create an rb it is unselected, ie. its a valid state.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12449743
That's a different issue. A single radio button is in any case a theoretical entity in a gui
0
 
LVL 92

Expert Comment

by:objects
ID: 12449756
Why would I be talking about a single radio button :-D
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12449769
I don't know but you were unless 'an rb' is plural in your world ..
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question