首页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();
    // Add rollover icon
    Icon rolloverIcon = new ImageIcon("r.gif");
    button.setRolloverIcon(rolloverIcon);

    // Add pressed icon
    Icon pressedIcon = new ImageIcon("p.gif");
    button.setPressedIcon(pressedIcon);

    // To remove rollover icon, set to null
    button.setRolloverIcon(null);

    // To remove pressed icon, set to null
    button.setPressedIcon(null);

    JOptionPane.showMessageDialog(null, button);
  }
}