JCheckBox: setRolloverSelectedIcon(Icon rolloverSelectedIcon) : JCheckBox « javax.swing « Java by API






JCheckBox: setRolloverSelectedIcon(Icon rolloverSelectedIcon)

  



import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {
    setSize(300, 300);
    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);
  }

  public static void main(String[] args) {
    new Main().setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.new JCheckBox(Action a)
2.new JCheckBox(String text)
3.new JCheckBox(String text, boolean selected)
4.new JCheckBox(String text, Icon normal)
5.JCheckBox: addActionListener(ActionListener lis)
6.JCheckBox: addChangeListener(ChangeListener lis)
7.JCheckBox: addComponentListener(ComponentListener l)
8.JCheckBox: addItemListener(ItemListener lis)
9.JCheckBox: isSelected()
10.JCheckBox: setBorderPaintedFlat(boolean b)
11.JCheckBox: setDisabledIcon(Icon disabledIcon)
12.JCheckBox: setDisabledSelectedIcon(Icon disabledSelectedIcon)
13.JCheckBox: setEnabled(boolean b)
14.JCheckBox: setIcon(Icon defaultIcon)
15.JCheckBox: setMnemonic(int mnemonic)
16.JCheckBox: setPressedIcon(Icon pressedIcon)
17.JCheckBox: setRolloverIcon(Icon i)
18.JCheckBox: setSelected(boolean b)
19.JCheckBox: setSelectedIcon(Icon i)
20.JCheckBox: setText(String text) (HTML)
21.JCheckBox: setToolTipText(String text)