0

How can I make a CheckBoxGroup of JCheckBox objects? I use:

CheckboxGroup cg = new CheckboxGroup();
JCheckBox c1 = new JCheckBox("A", false, cg);

But this gives:

The constructor JCheckBox(String, boolean, CheckboxGroup) is undefined

Everything is fine if I use a regular Checkbox though...

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    Use `JRadioButton` instead and add it to `ButtonGroup` –  Dec 11 '14 at 12:51
  • `CheckBoxGroup` is AWT API, for Swing, you want to use `ButtonGroup`. It doesn't, however, really make sense to use `JCheckBox` in groups as much as it does to use `JRadioButtons`... – MadProgrammer Dec 11 '14 at 13:14

1 Answers1

2

Look at this :

CheckboxGroup cbg = new CheckboxGroup();
add(new Checkbox("one", cbg, true));
add(new Checkbox("two", cbg, false));
add(new Checkbox("three", cbg, false));

CheckboxGroup is working with awt Checkbox. Group is the second parameter.

More: CheckboxGroup docs

Like Arvind said, it would be better to use JRadioButton

alex
  • 8,904
  • 6
  • 49
  • 75