Results 1 to 7 of 7
  1. #1
    Reborn is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default 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);

  2. #2
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    I had been trying the clearSelection method but wasn't really sure how to implement it.
    Can't understand your problem? Make it more clear.

  3. #3
    shai is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    If I understand you correctly (and I'm not sure I do), you want to deselect a radio button.

    You should use:
    Java Code:
    radiobutton.setSelected(false);
    Where radiobutton is your JRadioButton object.

    Hope this helps.

  4. #4
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    Ok, to deselect,
    Java Code:
    radiobutton.setSelected(false);
    does work. But I think OP is himself confused. Becoz he posted code that's not related to clearSelection.

    -Regards

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  6. #6
    Reborn is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    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;

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,452
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Reborn View Post
    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.
    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

  1. Radio Buttons - Reset - clear dot
    By dbashby in forum New To Java
    Replies: 6
    Last Post: 06-11-2014, 06:40 AM
  2. Disable Radio button
    By AJG in forum New To Java
    Replies: 3
    Last Post: 05-10-2011, 11:09 AM
  3. Radio Button help!
    By javanator in forum New To Java
    Replies: 3
    Last Post: 04-25-2010, 08:01 PM
  4. Radio button dot color
    By Psyclone in forum AWT / Swing
    Replies: 3
    Last Post: 02-21-2010, 04:29 AM
  5. How to use SWT Radio Button
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-25-2008, 02:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •