void (JComponent component) { @NlsSafe String actionName = "FCB_UP"; Action action = new AbstractAction(actionName) { private static final long serialVersionUID = 4555560696351340571L; @Override public void actionPerformed(ActionEvent e) { // if popup is not visible, just make it visible. // if popup has not the focus, pass it the focus // else: move up! if (popup.isVisible()) { if (popup.isPopupFocused()) { popup.selectUp(false); } else { popup.setPopupFocused(true); // if still not focused, it has empty content if (!popup.isPopupFocused()) { popup.hide(); } } } else { showChoices(); } } }; component.getActionMap().put(actionName, action); component.getInputMap(JComponent.WHEN_FOCUSED) .put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), actionName); }