Mega Code Archive

 
Categories / Java / Swing JFC
 

Adding a Disabled Icon to a JButton Component

import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; public class Main {   public static void main(String[] argv) throws Exception {     JButton button = new JButton();     // Icon will appear gray     button.setEnabled(false);     // Set a disabled version of icon     Icon disabledIcon = new ImageIcon("d.gif");     button.setDisabledIcon(disabledIcon);     // To remove the disabled version of the icon, set to null     button.setDisabledIcon(null);     button.setDisabledIcon(new ImageIcon("icon.gif"));   } }