Results 1 to 7 of 7
Thread: Clear Radio Button
- 07-25-2010, 04:43 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
Clear Radio Button
Need help !! I had been trying the clearSelection method but wasn't really sure how to implement it. Could someone help me with it ? This is my codes for the radio button. Is it necessary to call an event handler ?
ButtonGroup group = new ButtonGroup();
group.add(jRadioButton);
group.add(jRadioButton1);
ButtonGroup group1 = new ButtonGroup();
group1.add(jRadioButton2);
group1.add(jRadioButton3);
ButtonGroup group2 = new ButtonGroup();
group2.add(jRadioButton4);
group2.add(jRadioButton5);
ButtonGroup group3 = new ButtonGroup();
group3.add(jRadioButton6);
group3.add(jRadioButton7);
- 07-25-2010, 05:43 AM #2
Can't understand your problem? Make it more clear.I had been trying the clearSelection method but wasn't really sure how to implement it.
- 07-25-2010, 08:04 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
If I understand you correctly (and I'm not sure I do), you want to deselect a radio button.
You should use:
Where radiobutton is your JRadioButton object.Java Code:radiobutton.setSelected(false);
Hope this helps.
- 07-25-2010, 08:40 AM #4
Ok, to deselect,
does work. But I think OP is himself confused. Becoz he posted code that's not related to clearSelection.Java Code:radiobutton.setSelected(false);
-Regards
-
ButtonGroup#clearSelection() should work fine clearing the selection of all of the radio buttons held by that button group. I agree with the others in that you are not telling us what specific problems you are having with it.
Also, you might consider using an array of ButtonGroup objects if you need to clear all of them at once -- by iterating through the array and calling clearSelection on all ButtonGroup objects held in the array.
- 07-25-2010, 05:01 PM #6
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
Sorry, I want to create a Clear Button and when the user clicks that Button, the user could clear away all the selected radio buttons and select afresh again. Im unsure about how to put the clearSelection codes into the program.
private JButton getClearButton() {
if (ClearButton == null) {
ClearButton = new JButton();
ClearButton.setText("Clear");
ClearButton.setBounds(new Rectangle(343, 620, 101, 24));
ClearButton.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent e) {
clearSelection();}
private void clearSelection() {
}
});
}
return ClearButton;
- 07-25-2010, 05:21 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,417
- Blog Entries
- 7
- Rep Power
- 17
Did you actually read the previous replies? You want to clear (deselect) all radio buttons; those buttons are members of four groups (see your own original post). The ButtonGroup.clearSelection() method clears (deselects) the buttons in that group, so you should call that method for all four groups.
kind regards,
Jos
Similar Threads
-
Disable Radio button
By AJG in forum New To JavaReplies: 3Last Post: 05-10-2011, 11:09 AM -
Radio Button help!
By javanator in forum New To JavaReplies: 3Last Post: 04-25-2010, 08:01 PM -
Radio button dot color
By Psyclone in forum AWT / SwingReplies: 3Last Post: 02-21-2010, 04:29 AM -
Radio Buttons - Reset - clear dot
By dbashby in forum New To JavaReplies: 5Last Post: 10-14-2009, 12:17 AM -
How to use SWT Radio Button
By Java Tip in forum SWTReplies: 0Last Post: 07-25-2008, 02:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks