I tried using getInputMap () + getActionMap () on a JComboBox and it seems to have no effect.
I tried addActionListener () / addItemListener () on a JComboBox, and I cannot distinguish the selection change from someone pressing the Return / Enter key.
Any suggestions? In my application, I want the Return / Enter key to be stronger than just a choice, it's a choice + action.
Here is my code for setting key binding. It works fine (for example, note("hit ENTER")is called) when the component is JList, but does not work when the component is a JComboBox.
private void setupApplyProfile(final JComponent component, final MyComboBoxModel mcbm)
{
String enterAction = "applyItem";
KeyStroke enterKey = KeyStroke.getKeyStroke("ENTER");
component.getInputMap().put(enterKey, enterAction);
component.getActionMap().put(enterAction, new AbstractAction()
{
@Override public void actionPerformed(ActionEvent e) {
note("hit ENTER");
applySelectedProfile(mcbm);
}
});
}
source
share