首页javajbuttonJava Swing - 如何请将禁用图标添加到JButton

Java Swing - 如何请将禁用图标添加到JButton

我们想知道如何请将禁用图标添加到JButton。
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class Main {
  public static void main(final String args[]) {
    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"));

    JOptionPane.showMessageDialog(null, button);
  }
}