Eclipse WindowsBuilder: being able to select only 1 checkbox and not all at once

0

Hello, I have that program ready but, you can select all the checkboxes at the same time and I do not want that. Is there any way that only 1 can be selected at a time?

For example, in my case it would be:

  • Case 1: Provincial, Strip 1, 2 and 3. Local deactivated.
  • Case 2: Local, all others disabled.
asked by Robert Gomez 13.11.2016 в 15:34
source

2 answers

0

Define a RadioButton:

JRadioButton rbtn1=new JRadioButton("txt1",true);
JRadioButton rbtn2=new JRadioButton("txt2",false);
JRadioButton rbtn3=new JRadioButton("txt3",false);

Button Group Creation:

ButtonGroup grupo1 = new ButtonGroup();
grupo1.add(rbtn1);
grupo1.add(rbtn2);
grupo1.add(rbtn3);

The Class that is used is called JRadioButton The parameters that are passed at the moment of creating it are the Text that will be carried and if this item will be selected when executing our program.

examples:

rbtn1.setText("Texto");
rbtn1.setSelected(true);

to perform an action:

if(rbtn1.isSelected()==true)
{
 System.out.print("Seleccionó opción 1");
}
    
answered by 13.11.2016 / 17:52
source
1

Try to do it with JRadioButton instead of a CheckBox, the RadioButtons have the facility to differentiate them by group so you can have them select only 1 option per group! Greetings:)

    
answered by 13.11.2016 в 16:10