Add disable icon for JCheckBox in Java
Description
The following code shows how to add disable icon for JCheckBox.
Example
//from w ww. j ava 2 s . com
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");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JCheckBox ac = new JCheckBox("A/C");
Icon i = new ImageIcon("a.gif");
ac.setDisabledIcon(i);
frame.add(ac);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »