JButton btnNewButton = new JButton("New button");
btnNewButton.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "sdfsaf");
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_F6,0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
红色处如果不使用其他组合键就用0代替,需要组合键时直接使用修饰符(例如KeyEvent.CTRL_DOWN_MASK)替换0