Java Swing: 为JButton设置ctrl 快捷键

//保存按钮——实际上,如果要JMenu的话,完全可以不必来这一套,直接在jMenuItem里设置快捷键就可以了...
        this.jButton_save.registerKeyboardAction(new SaveListener(), KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);

//保存按钮的action
    class SaveListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {//保存到xml
            new WriteXML(XMLCraft.fileName, XMLCraft.configName, XMLCraft.oneName, XMLCraft.xmlNames).write(((javax.swing.table.DefaultTableModel) jTable1.getModel()).getDataVector());
        }
    }

你可能感兴趣的:(java,xml,swing)