void (String shortcut, Predicate<? super JTable> predicate) { Object actionKey = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).get(KeyStroke.getKeyStroke(shortcut)); Action action = getActionMap().get(actionKey); getActionMap().put(actionKey, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (!predicate.test(JBTable.this)) { action.actionPerformed(e); } } }); }