Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 325
Cheesegraterr Avatar asked Dec 07 '11 20:12

Cheesegraterr


People also ask

How do I know if JCheckBox is checked?

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.

Which method of JCheckBox tells you if a checkbox is checked Mcq?

Use the isSelected method. You can also use an ItemListener so you'll be notified when it's checked or unchecked.

How do I create a true checkbox in Java?

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.


1 Answers

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

like image 160
Laf Avatar answered Sep 26 '22 08:09

Laf