HanRui
asked on
Clearing a selection in a Checkboxgroup
I have a checkboxgroup, myGroup with individual boxes male, female.
I want a "clear" function to reset the choice to null. Nothing works. setState(false) does not work for me on myGroup or male, female.
How can I do that?
I want a "clear" function to reset the choice to null. Nothing works. setState(false) does not work for me on myGroup or male, female.
How can I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points :)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class Test
{
CheckboxGroup myGroup = new CheckboxGroup();
public Test()
{
Checkbox male = new Checkbox("Male", myGroup, false);
Checkbox female = new Checkbox("Female", myGroup, false);
male.setFont(new Font("Dialog", 1, 14));
male.setLocation(20, 10);
male.setSize(80, 30);
female.setFont(new Font("Dialog", 1, 14));
female.setLocation(20, 40);
female.setSize(80, 30);
JButton button = new JButton("Deselect All");
button.setLocation(10, 80);
button.setSize(100, 45);
button.setBorder(new BevelBorder(BevelBorder.RA
button.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEven
{
// this is where you set the selected
// checkbox to null, or none
myGroup.setSelectedCheckbo
}
}
);
JFrame frame = new JFrame();
frame.setLocation(300, 300);
frame.setSize(120, 155);
frame.setResizable(false);
frame.getContentPane().set
frame.getContentPane().add
frame.getContentPane().add
frame.getContentPane().add
frame.setVisible(true);
}
public static void main(String[] args)
{
new Test();
}
}
Hope this helps.