void () { final Action copy = getActionMap().get("copy"); if (copy == null || copy instanceof UIResource) { Action newCopy = new AbstractAction() { @Override public boolean isEnabled() { return getSelectedIndex() != -1; } @Override public void actionPerformed(ActionEvent e) { doCopyToClipboardAction(); } }; getActionMap().put("copy", newCopy); } }