I have found a very simple way to solve this.
The JComboBox default editor has an internal class BasicComboBoxEditor$BorderlessTextField that is the component that gets and loses focus.
It can be accessed simply by
Component component = comboBox.getEditor().getEditorComponent();
if (component instanceof JTextField)
JTextField borderlesstextfield = (JTextField) borderless;
Then add a focus listener like you would to 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 gain and loss of focus for the ComboBox
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…