e751. adding a rollover and pressed icon to a jbutton component.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 24 行
TXT
24 行
The rollover icon is displayed when the cursor is moved over the button. If no rollover icon is set, the default icon is displayed when the cursor is moved over the button.
The pressed icon is displayed when the button is armed (i.e., the mouse button is down while the cursor is on the button). If no pressed icon is set, the default icon is displayed when the button is armed.
The rollover and pressed icons are never displayed if the button is disabled.
// To create a button with an icon, see e746 Adding an Icon to a JButton Component
// Add rollover icon
Icon rolloverIcon = new ImageIcon("ricon.gif");
button.setRolloverIcon(rolloverIcon);
// Add pressed icon
Icon pressedIcon = new ImageIcon("picon.gif");
button.setPressedIcon(pressedIcon);
// To remove rollover icon, set to null
button.setRolloverIcon(null);
// To remove pressed icon, set to null
button.setPressedIcon(null);
Related Examples
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?