AutoCompleteSupport: JComboBox.setSelectedItem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

AutoCompleteSupport: JComboBox.setSelectedItem

Holger
Hey James,

I noticed the following problem when setting a value programmatically
with JComboBox.setSelectedItem:

Take the AutoCompleteSupportTestApp and change the SetValueProgrammaticallyActionHandler
to:
        public void actionPerformed(ActionEvent e) {
//            this.comboBox.setSelectedItem(URL_SAMPLE_DATA[URL_SAMPLE_DATA.length-1]);
            this.comboBox.setSelectedItem(URL_SAMPLE_DATA[6]);
        }

E.g. it should select the item "http://java.sun.com/".
But the result is, that the item "http://java.sun.com/javase/6/" is selected,
probably because AutoCompleteFilter.selectAutoCompleteTerm is called during
this operation, which finds and selects the first matching element.
Why is this a problem?
Imagine the editing of an existing object which has a preset member value
of ""http://java.sun.com/" and is bound to the JComboBox with AutoCompleteSupport.
The ComboBox would show "http://java.sun.com/javase/6/" as the member value, which
is not correct.
So in this case, the exact element should be searched first and when found selected in the
JComboBox. If there is no equal element in the ComboBoxModel, then you can autocomplete
the term to find another matching element.

What do you think?

Holger

_______________________________________________________________________
Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und kostenlos.
Gleich testen! http://www.pc-sicherheit.web.de/freescan/?mc=022222

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AutoCompleteSupport: JComboBox.setSelectedItem

James Lemieux
Agreed Holger. I actually fixed a narrower version of this bug a while ago. Specifically, selecting

"<a href="http://java.sun.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://java.sun.com/ "

out of the dropdown with the mouse would immediately autocomplete to

"<a href="http://java.sun.com/javase/6/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://java.sun.com/javase/6/"

if they were out of alphabetical order in the ComboBoxModel (as our sample data now is). And now you've found a similar defect that can occur due to programmatic selection.

I've delivered a fix for the bug that is straightfoward and does exactly what you proposed (your analysis was quite good). When locating autocomplete terms we prefer to use EXACT matches, and fallback to "the first partial match" we located. The fix was a little bit involved as I wanted to keep identical behaviour when typing new characters OR deleting characters (that is, we prefer to select exact matches, if possible, even when deleting characters). I think I've achieved it without introducing bugs, but the fix was a little inelegant, and so I hope that I didn't break some other cases with this fix.

I'll create some jars later on this weekend. Thanks for the bug report!

James


On 9/2/06, Holger Brands <[hidden email]> wrote:
Hey James,

I noticed the following problem when setting a value programmatically
with JComboBox.setSelectedItem:

Take the AutoCompleteSupportTestApp and change the SetValueProgrammaticallyActionHandler
to:
        public void actionPerformed(ActionEvent e) {
//            this.comboBox.setSelectedItem(URL_SAMPLE_DATA[URL_SAMPLE_DATA.length-1]);
            this.comboBox.setSelectedItem(URL_SAMPLE_DATA[6]);
        }

E.g. it should select the item "<a href="http://java.sun.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://java.sun.com/".
But the result is, that the item "<a href="http://java.sun.com/javase/6/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://java.sun.com/javase/6/" is selected,
probably because AutoCompleteFilter.selectAutoCompleteTerm is called during
this operation, which finds and selects the first matching element.
Why is this a problem?
Imagine the editing of an existing object which has a preset member value
of ""<a href="http://java.sun.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://java.sun.com/" and is bound to the JComboBox with AutoCompleteSupport.
The ComboBox would show "<a href="http://java.sun.com/javase/6/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://java.sun.com/javase/6/" as the member value, which
is not correct.
So in this case, the exact element should be searched first and when found selected in the
JComboBox. If there is no equal element in the ComboBoxModel, then you can autocomplete
the term to find another matching element.

What do you think?

Holger

_______________________________________________________________________
Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und kostenlos.
Gleich testen! <a href="http://www.pc-sicherheit.web.de/freescan/?mc=022222" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://www.pc-sicherheit.web.de/freescan/?mc=022222

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: AutoCompleteSupport: JComboBox.setSelectedItem

Holger
In reply to this post by Holger
Hey James,

>
> I'll create some jars later on this weekend. Thanks for the bug report!
>
> James
>

Thanks for the quick bugfix. I've already tested it from CVS.
It works great for me, now.
But I noticed a failing testcase:

AutoCompleteSupportTest.guiTestDeleteKey


Thanks,
Holger

_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AutoCompleteSupport: JComboBox.setSelectedItem

James Lemieux
Fixed. In this case the test case was working and the code was broken (the delete key for strict mode). Yay test cases.

James

On 9/3/06, Holger Brands <[hidden email]> wrote:
Hey James,

>
> I'll create some jars later on this weekend. Thanks for the bug report!
>
> James
>

Thanks for the quick bugfix. I've already tested it from CVS.
It works great for me, now.
But I noticed a failing testcase:

AutoCompleteSupportTest.guiTestDeleteKey


Thanks,
Holger

_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]