Set pressed icon for JCheckBox in Java
Description
The following code shows how to set pressed icon for JCheckBox.
Example
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
public class Main{
public static void main(String[] argv){
JFrame frame = new JFrame("JCheckBox Test");
//from w ww. j av a 2 s . co m
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JCheckBox ac = new JCheckBox("A/C");
Icon i = new ImageIcon("a.gif");
ac.setPressedIcon(i);
frame.add(ac);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »