Example usage for javax.swing JCheckBox JCheckBox

List of usage examples for javax.swing JCheckBox JCheckBox

Introduction

In this page you can find the example usage for javax.swing JCheckBox JCheckBox.

Prototype

public JCheckBox() 

Source Link

Document

Creates an initially unselected check box button with no text, no icon.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JCheckBox checkbox = new JCheckBox();

    String label = "<html><table cellpadding=0><tr><td><img src=file:" + "icon.gif" + "/></td><td width=" + 3
            + "><td>"

            // Retrieve the current label text
            + checkbox.getText() + "</td></tr></table></html>";

    // Add the icon
    checkbox.setText(label);/*from w w w .j ava 2s.  c om*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JCheckBox checkbox = new JCheckBox();

    // Get the current state of the checkbox
    boolean b = checkbox.isSelected();

    // Set the state of the checkbox to off
    checkbox.setSelected(false);/*w  w  w . j av a2s  .c  om*/

    // Set the state of the checkbox to on
    checkbox.setSelected(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JCheckBox checkbox = new JCheckBox();

    Icon pressedIcon = new ImageIcon("pres-icon.gif");
    checkbox.setPressedIcon(pressedIcon);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JCheckBox checkbox = new JCheckBox();

    Icon rollIcon = new ImageIcon("roll-icon.gif");
    checkbox.setRolloverIcon(rollIcon);//  w  w  w . j  a v  a  2  s  .  c  o  m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    JCheckBox checkbox = new JCheckBox();

    // Set the unselected state icon
    Icon unselDisIcon = new ImageIcon("nosel-dis-icon.gif");
    checkbox.setDisabledIcon(unselDisIcon);

    // Set the selected state icon
    Icon selDisIcon = new ImageIcon("sel-dis-icon.gif");
    checkbox.setDisabledSelectedIcon(selDisIcon);

}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Editable Tree");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" };
    JTree tree = new JTree(array);
    tree.setEditable(true);//  w  w w  . j  a v a  2  s .  c om
    tree.setRootVisible(true);
    JCheckBox checkBox = new JCheckBox();
    TreeCellEditor editor = new DefaultCellEditor(checkBox);
    tree.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:TreeEdit.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; // Hello will map to false
    JTree tree = new JTree(array);
    tree.setEditable(true);/*from  ww w.j  a v  a  2s.  c o  m*/
    tree.setRootVisible(true);

    JCheckBox checkBox = new JCheckBox();

    TreeCellEditor editor = new DefaultCellEditor(checkBox);
    tree.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static JCheckBox createCheckBox() {
    final JCheckBox c = new JCheckBox();
    configureActiveComponent(c);/*from   w  w  w  .j av a2s  . c o  m*/

    return c;
}

From source file:Main.java

/**
 * Creates a new <code>JCheckBox</code> object with the given properties.
 *
 * @param bounds The dimension of the check box
 * @return A <code>JCheckBox</code> object
 *//*from   w  w  w .j  a  v a2 s. c o m*/
public static JCheckBox createJCheckBox(Rectangle bounds) {
    JCheckBox jCheckBox = new JCheckBox();
    jCheckBox.setBounds(bounds);
    return jCheckBox;
}

From source file:Main.java

public Main() {
    // Add check boxes to the content pane.
    Icon normal = new MyIcon(Color.red);
    Icon rollover = new MyIcon(Color.YELLOW);
    Icon selected = new MyIcon(Color.BLUE);

    JCheckBox cb = new JCheckBox();
    cb.setRolloverIcon(rollover);/*w w  w . ja  v  a2 s  .  c o m*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}