Skip to main content

Adding Autocomplete to JCombo causes FocusListener issues

2 replies [Last post]
ggranum
Offline
Joined: 2006-02-27
Points: 0

Adding Autocomplete to JCombo causes FocusListener issues:
for the most part I am/was concerned with the DropDown failing to close when the user Tabs out of the ComboField.

I looked pretty hard, but honestly have no true idea how to fix it correctly. My only guess would be to add a few lines in Configurator:
// in the method:
// public static void enableAutoCompletion(final JComboBox comboBox) {

// code
editor.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
jcombo.setPopupVisible(false);
}
});

// end code.

Which is to say, that is how *my* code makes the popup close. And it works. But I don't understand *why* I need to do it.

The real issue is harder to define: why does the extraction and use of the Editor (via comboBox.getEditor().getEditorComponent()) cause the JComboBox to stop correctly handling of FocusEvents and such (using an InputVerfier on the combobox directly fails also; presumably closely related)?

Any focus related Listeners must be placed on the ComboBox's editor after utilizing the Configurator methods. I would LOVE to know what is happening, exactly, as I traced the code back and couldn't find an answer on my own.

In my mind, it would be advisable to either work around this (says the man not writing the code), or to add some comments to the effect on the Configurator methods.

Thanks,
Geoff Granum

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bierhance
Offline
Joined: 2003-06-11
Points: 0

Hi Geoff,

Thanks for your feedback! It might be possible that the observed behaviour is caused by

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5100422

Are you sure the problem is related to the autocompletion feature and not related to this bug?

Warm regards,
Thomas

ggranum
Offline
Joined: 2006-02-27
Points: 0

Ding, right on the money. Thanks.

What tricked me was the 'jcombo.setEnabled(false)' -- of course, the bug doesn't show up when a combobox isn't editable, but I had set the field NOT editable to enforce strict matching; when I commented out the Configurator line it seemed to fix the bug, when in fact it was just that the combo box was not being set to editable by the Configurator.

Thanks again,
Geoff