Skip to main content

AutoCompleteComboBox

6 replies [Last post]
hamu
Offline
Joined: 2007-04-27

Hi

I like it and its good. But on a none strict AutoCompleteCombo when you type it a particular letter for eg. 'p' it selects the first 'p' item in the list but wouldnot scroll it to the top and it remains at the bottom. Please note that i tried it with letter 'p' and it might scroll to the top with another item. Thus the question is it doesent scroll to the top with all of it. Why is this not possible.

This is a feature in microsoft ComboBoxes where all the 'p' items are displayed with the first 'p' item as the top most item in the combobox popup list.

Please can you make any suggestion as to whether this is possible and if not a solution to achieve this behaviour.

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08

I have begun coding a solution, but it causes spurious ItemEvents to be created.

Here's the new code for ComboBoxAdaptor:
[code] public void setSelectedItem(Object item) {
// this next line tricks the display into placing the real selected item
// as close to the top of the list as possible, SwingX #548
// TODO creates spurious itemevents
comboBox.setSelectedIndex(comboBox.getItemCount() - 1);
comboBox.setSelectedItem(item);
}[/code]
The problem is that setting the index to the end and then resetting it to the correct one, I generate ItemEvents to the selection and deselection of the last item.

Does anyone have any ideas on how I can avoid generating the extra events?

Karl

kschaefe
Offline
Joined: 2006-06-08

Do you have a test case for this behavior?

Karl

hamu
Offline
Joined: 2007-04-27

Hi

Thanks for that.

You can se e this behaviour within the Demo download package from SwingLabs.

Please try that. If you need help let me know.

Thanks

kschaefe
Offline
Joined: 2006-06-08

I see the behavior that you are describing in the demo. It is scrolling the line into the visible area in the closest way possible. For instance in the demo, type 'p', then clear the choice and type 'j'. J will appear at the top because it was going bottom up since the current focus was below J. However if you start from the top (type 'a' and then clear it), typing 'j' will place it at the bottom because we're looking top down. I agree that the behavior should be consistant. And, like the Microsoft example you sited, I believe scrolling to top is the correct way to do it.

The interesting thing is that not all look and feels may want this behavior. In fact, I could imagine a case where the current behavior is accurate or a bottom-only behavior is correct. AutoComplete uses the decorator pattern, so there are some interesting questions about how to handle L&F delegates and how to allow L&F delegates to interact and configure the AutoComplete.

For now, I think that you should file a RFE. Please site this forum thread in the request, so that we don't loose track of it.

Karl

hamu
Offline
Joined: 2007-04-27

Thanks for that and that was very informative.

Did you mean an RFE with swing labs?

Thanks

kschaefe
Offline
Joined: 2006-06-08

> Did you mean an RFE with swing labs?
Yes. You can do so here:
https://swingx.dev.java.net/issues/

Karl