Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 960
justanother1 Avatar asked May 30 '12 17:05

justanother1


3 Answers

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)
like image 54
dshapiro Avatar answered Oct 01 '22 07:10

dshapiro


Do you mean how to check if Checkbox is selected or not, if yes then use isSelected

boolean isSelected = jCheckBox.isSelected();

if(isSelected ){
   jCheckBox.setSelected(false);
} else {
   jCheckBox.setSelected(true);
}
like image 40
mprabhat Avatar answered Oct 01 '22 08:10

mprabhat


There is an awesome tutorial from Sun that you can read to complete your knowledge. If you want to know the current selection state of a JCheckbox, just use the method isSelected().

like image 2
rlinden Avatar answered Oct 01 '22 07:10

rlinden