Example usage for javax.swing JCheckBox setSelectedIcon

List of usage examples for javax.swing JCheckBox setSelectedIcon

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "The selected icon for the button.")
public void setSelectedIcon(Icon selectedIcon) 

Source Link

Document

Sets the selected icon for the button.

Usage

From source file:CheckBoxIcon.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon checked = new CheckBoxIcon();
    Icon unchecked = new CheckBoxIcon();
    JCheckBox aCheckBox1 = new JCheckBox("Pizza", unchecked);
    aCheckBox1.setSelectedIcon(checked);
    JCheckBox aCheckBox2 = new JCheckBox("Calzone");
    aCheckBox2.setIcon(unchecked);//w w w .  j a v a 2 s .  co  m
    aCheckBox2.setSelectedIcon(checked);
    Icon checkBoxIcon = new CheckBoxIcon();
    JCheckBox aCheckBox3 = new JCheckBox("Anchovies", checkBoxIcon);
    JCheckBox aCheckBox4 = new JCheckBox("Stuffed Crust", checked);
    frame.setLayout(new GridLayout(0, 1));
    frame.add(aCheckBox1);
    frame.add(aCheckBox2);
    frame.add(aCheckBox3);
    frame.add(aCheckBox4);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:CheckBoxIcon.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Iconizing CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon checked = new CheckBoxIcon();
    Icon unchecked = new CheckBoxIcon();
    JCheckBox aCheckBox1 = new JCheckBox("Pizza", unchecked);
    aCheckBox1.setSelectedIcon(checked);
    JCheckBox aCheckBox2 = new JCheckBox("Calzone");
    aCheckBox2.setIcon(unchecked);/*from w  ww.ja v  a2  s . c  o m*/
    aCheckBox2.setSelectedIcon(checked);
    Icon checkBoxIcon = new CheckBoxIcon();
    JCheckBox aCheckBox3 = new JCheckBox("Anchovies", checkBoxIcon);
    JCheckBox aCheckBox4 = new JCheckBox("Stuffed Crust", checked);
    frame.setLayout(new GridLayout(0, 1));
    frame.add(aCheckBox1);
    frame.add(aCheckBox2);
    frame.add(aCheckBox3);
    frame.add(aCheckBox4);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:IconCheckBoxSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Iconizing CheckBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Icon checked = new DiamondIcon(Color.black, true);
    Icon unchecked = new DiamondIcon(Color.black, false);
    JCheckBox aCheckBox1 = new JCheckBox("Pizza", unchecked);
    aCheckBox1.setSelectedIcon(checked);
    JCheckBox aCheckBox2 = new JCheckBox("Calzone");
    aCheckBox2.setIcon(unchecked);/*  ww  w . ja v  a  2  s  . c om*/
    aCheckBox2.setSelectedIcon(checked);
    Icon checkBoxIcon = new CheckBoxIcon();
    JCheckBox aCheckBox3 = new JCheckBox("Anchovies", checkBoxIcon);
    JCheckBox aCheckBox4 = new JCheckBox("Stuffed Crust", checked);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(0, 1));
    contentPane.add(aCheckBox1);
    contentPane.add(aCheckBox2);
    contentPane.add(aCheckBox3);
    contentPane.add(aCheckBox4);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

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  .j av  a2s .  c  o m
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

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(normal);
    cb.setRolloverIcon(rollover);/*from ww  w.j a va 2  s .  c om*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

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(normal, true);
    cb.setRolloverIcon(rollover);/*from ww w  .  j  a  v a 2 s . c  o m*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

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("www.java2s.com", normal);
    cb.setRolloverIcon(rollover);//w w w  . ja v a2s  . co m
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:MainClass.java

public MainClass() {
    // 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("www.java2s.com", normal);
    cb.setRolloverIcon(rollover);/*from ww w  .  j  av  a  2  s  .co  m*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

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("www.java2s.com", normal, true);
    cb.setRolloverIcon(rollover);//from www. j a  v  a  2  s. co  m
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:JCheckBoxCustomIcon.java

public JCheckBoxCustomIcon() {
    setSize(300, 300);//from www  . j  a va 2 s .  c om
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    JCheckBox checkBox = new JCheckBox("Check me!");
    checkBox.setSelected(true);

    // Set default icon for checkbox
    checkBox.setIcon(new ImageIcon("icon.png"));
    // Set selected icon when checkbox state is selected
    checkBox.setSelectedIcon(new ImageIcon("selectedIcon.png"));
    // Set disabled icon for checkbox
    checkBox.setDisabledIcon(new ImageIcon("disabledIcon.png"));
    // Set disabled-selected icon for checkbox
    checkBox.setDisabledSelectedIcon(new ImageIcon("disabledSelectedIcon.png"));
    // Set checkbox icon when checkbox is pressed
    checkBox.setPressedIcon(new ImageIcon("pressedIcon.png"));
    // Set icon when a mouse is over the checkbox
    checkBox.setRolloverIcon(new ImageIcon("rolloverIcon.png"));
    // Set icon when a mouse is over a selected checkbox
    checkBox.setRolloverSelectedIcon(new ImageIcon("rolloverSelectedIcon.png"));

    getContentPane().add(checkBox);
}