I found a very simple way to solve this problem.
The default JComboBox editor has an internal class BasicComboBoxEditor $ BorderlessTextField, which is a component that gains and loses focus.
You can access it simply
Component component = comboBox.getEditor().getEditorComponent(); if (component instanceof JTextField) JTextField borderlesstextfield = (JTextField) borderless;
Then add a focus listener like any JTextField
borderlesstextfield.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { } }});
Now you have a FocusListener that will respond as expected to win and lose focus for the ComboBox
Fred Andrews
source share