Java Swing How to - Display an icon when the cursor is moved over the checkbox








Question

We would like to know how to display an icon when the cursor is moved over the checkbox.

Answer

/*from  w ww .ja va  2 s .c  om*/


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 rollIcon = new ImageIcon("roll-icon.gif");
    checkbox.setRolloverIcon(rollIcon);

  }
}