Search code examples
javaswingawtjcheckbox

Evaluating Checkbox Boolean Value


I'm sure this is a rediculously easy question, but I just can't find the answer to it anywhere. I have a JCheckbox that I need to evaluate the boolean value of, and then change the value with an if statement. The problem is I just can't find the syntax anywhere for evaluating the contents of a JCheckbox, let alone changing it. This will probably be really easy one, but I just can't seem to find anything helpful. Thanks!


Solution

  • This SO thread sort of answers your question. If your JCheckBox is named "Foo", you would check its value with

    Foo.isSelected()
    

    To set its value, you would use

    Foo.setSelected(true)