1

I have a method that generates a JPanel with one checkBox. The method has 3 parameters, one of them is a Boolean value that is null. When I use the Boolean parameter into ActionEvent, the system don't recognize it. Also, I use if look because I want that the user could select and unselect the checkBox. Unfortunately, the system never enter when checkBox isSelected. Could you help me, please?

private JPanel getThirdPanelBox(String elementList, String title, Boolean valueMant) {
    JPanel thirdPanelBox = new JPanel();
    thirdPanelBox.setLayout(new BorderLayout());
    thirdPanelBox.add(new JLabel(elementList), BorderLayout.CENTER);

    JCheckBox elementListCheckBox = new JCheckBox();
    elementListCheckBox.setSelected(false);
    elementListCheckBox.addActionListener(actionEvent -> {

        if (elementListCheckBox.isSelected())
            valueMant = true;
        else
            valueMant = false;
    });
    thirdPanelBox.add(elementListCheckBox, BorderLayout.WEST);
    return thirdPanelBox;
}
samabcde
  • 6,988
  • 2
  • 25
  • 41
Jeanette
  • 11
  • 1
  • a boolean is just that. You can add an actionlistener to the checkbox, instead, if that is what you are trying to do. – Stultuske Dec 11 '20 at 08:26
  • Please try to rephrase your question, update description like "the system don't recognize it. "(what you mean recognize it?), "Also, I use if look "(what is if look?), "the system never enter"(never enter what?, do you mean `elementListCheckBox.isSelected()` never return true?) – samabcde Dec 11 '20 at 11:55
  • Sorry, I'm new in Java. The programs shows error when I use the parameter valueMant into the if statement: valueMant=true, and also in the else statement: valueMant=false. – Jeanette Dec 11 '20 at 16:17
  • In addition, when I runs the program, never takes elementListCheckBoc.isSelected()=true. – Jeanette Dec 11 '20 at 16:19

0 Answers0