I am using a single JCheckBox
as an un-editable indicator for when something happens in my program. Right now I have this:
public void update(Observable o, Object arg) {
try {
if (Controller.c.turn.equals(this)) {
tp.turnCheckBox.setBorderPainted(true);
}
else {
tp.turnCheckBox.setBorderPainted(false);
}
} catch (Exception e) {
}
Basically, instead of painting the turnCheckBox
border... I want to have a checkmark in it.
It seems like it would be a simple pre-made method, maybe I am missing something but I can't get it to happen.
A checkmark will be used to choose a box. JCheckBox often uses the methods isSelected and setSelected. To select, or un-select, a box, use the setSelected(boolean) method. To check if a box is selected, use the isSelected() method.
Use the isSelected method. You can also use an ItemListener so you'll be notified when it's checked or unchecked.
If you want to set it to checked and disabled you have use setEnabled() which takes boolean as it's parameters. Example. option3. setChecked(true); option3.
Using tp.turnCheckBox.setSelected (boolean isSelected)
will check (or uncheck) the checkbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With