how to set JCheckBox to have a check mark, or not within a program

Cheesegraterr picture Cheesegraterr · Dec 7, 2011 · Viewed 54.6k times · Source

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.

Answer

Laf picture Laf · Dec 7, 2011

Using tp.turnCheckBox.setSelected (boolean isSelected) will check (or uncheck) the checkbox.