⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e746. adding an icon to a jbutton component.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
If the action used to create the button contains an icon, the button will be created using that icon. The icon will appear to the left of the text; to change the icon's position, see e747 Moving the Icon in a JButton Component. 
    // Retrieve the icon
    Icon icon = new ImageIcon("icon.gif");
    
    // Create an action with an icon
    Action action = new AbstractAction("Button Label", icon) {
        // This method is called when the button is pressed
        public void actionPerformed(ActionEvent evt) {
            // Perform action
        }
    };
    
    // Create the button; the icon will appear to the left of the label
    JButton button = new JButton(action);

If the action does not have an icon or a different icon must be used, add or change the icon using setIcon(): 
    // Add or change the icon; it will appear to the left of the text
    button.setIcon(icon);
    
    // Set to null to remove icon
    button.setIcon(null);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -