As you can see the code illustrated above creates two Action objects one is for entering and the other is for cancelling. The part of the code which is made bold is giving me problems.Code:Action enterSelection = new AbstractAction("ENTER"){ public void actionPerformed(ActionEvent e){ SearchInterface search = (SearchInterface) table.getModel(); if (table.getSelectedRow() == -1 ){ tfFind.requestFocus(); } else { search.selectRow(table.getSelectedRow()); closeDialog(); } } }; table.getInputMap(JComponent.WHEN_FOCUSED).put( KeyStroke.getKeyStroke("ENTER"), enterSelection.NAME); table.getActionMap().put(enterSelection.NAME, enterSelection); btnOK.addActionListener(enterSelection); Action cancelAction = new AbstractAction("CANCEL"){ public void actionPerformed(ActionEvent e){ SearchInterface search = (SearchInterface) table.getModel(); search.setCancelled(true); closeDialog(); } }; contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke("ESCAPE"), cancelAction.NAME); contentPane.getActionMap().put(cancelAction.NAME, cancelAction); table.getInputMap(JComponent.WHEN_FOCUSED).put( KeyStroke.getKeyStroke("ESCAPE"), cancelAction.NAME); table.getActionMap().put(cancelAction.NAME, cancelAction); btnCancel.addActionListener(cancelAction);
table object has two keystrokes associated with it one is for escape the other is for entering. both of which should trigger when table is focused. But whenever I do either of the keystrokes only the latter action which is the cancel is executed.
Question 1: Can there be only one keystroke associated with a component with the same condition (JComponent.WHEN_FOCUSED)?


Reply With Quote
