Java Swing How to - Set pressed icon for JCheckBox








Question

We would like to know how to set pressed icon for JCheckBox.

Answer

//from  w  w w .j  ava 2  s  .c  o m
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;

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

    JCheckBox checkbox = new JCheckBox();

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

  }
}