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.

Add disable icon for JCheckBox in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer