-1

I want to deselect a checkbox when i click the Clear button. the below code doesn't work.

        jCheckBox1.setSelected(false);

        jCheckBox2.setSelected(false);

        jCheckBox3.setSelected(false);

        jCheckBox4.setSelected(false);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jhi
  • 11
  • 1
  • 1
  • 2

1 Answers1

1

it worked and have no problem ,

For example:

final JCheckBoxcb1 = new JCheckBox("A");
final JCheckBoxcb2 = new JCheckBox("B");
JPanel panel = new JPanel();
JFrame frame = new JFrame("");
Button boton = new Button("Clear");
panel.add(boton);
panel.add(cb1);
panel.add(cb2);
frame.add(panel);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
boton.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
      cb1.setSelected(false);
      cb2.setSelected(false);
     }
  });
Alya'a Gamal
  • 5,624
  • 19
  • 34
  • `javax.swing.JCheckBox` does have `setSelected()` method [Java API SWING](http://docs.oracle.com/javase/6/docs/api/javax/swing/JCheckBox.html) but you may be talking about other class – icrovett Apr 04 '13 at 14:03