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

📄 e857. enabling an action.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
Actions can be bound to many different kinds of components. When an action is enabled or disabled, components that are bound to that action may automatically alter its display to match the enabled state of the action. This example creates three components: a button, a text component, and a menu item - - all bound to the same action. When the action is disabled, the button and menu item will appear disabled and the text component will not be able to invoke the action. 
    JFrame frame = new JFrame();
    
    // Button
    JButton button = new JButton(action);
    
    // Text Component
    JTextField textfield = new JTextField();
    textfield.getInputMap(JComponent.WHEN_FOCUSED).put(
        KeyStroke.getKeyStroke("F2"), action.getValue(Action.NAME));
    textfield.getActionMap().put(action.getValue(Action.NAME), action);
    
    // Menu Item
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu Label");
    menu.add(new JMenuItem(action));
    menuBar.add(menu);
    frame.setJMenuBar(menuBar);
    
    // The action
    public Action action = new AbstractAction("Action Name") {
        public void actionPerformed(ActionEvent evt) {
            // Perform action
        }
    };

⌨️ 快捷键说明

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