Just an fyi, one of the colleagues of mine suggested this solution:
overwrite the equals method in the custom class I was using. Amazingly, it
solved the problem.

-----Original Message-----
From: Dmitry Beransky [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 03, 2002 3:56 PM
To: '[EMAIL PROTECTED]'
Subject: RE: Java Swing/JComboBox Question.


At 12:00 PM 1/3/2002, Reinstein, Lenny wrote:
>You are right, partially Here is the updated question:
>
>The reason this happens is that the JComboBox is editable and I use the the
>text field of the ComboBox to implement auto-complete
>(I use getEditor().getEditorComponent() to the the text component that
>corresponds to the editable/selected item).

Oh, I see.  I assume you're using the default editor component.  If so, 
here's what happens:  when you type the text into the combo editor and hit 
enter, it generates an action event;  this action event is picked up by 
JComboBox's controller, that, in turn, calls getItem() on the editor 
component to get the newly entered string and, then, passes the returned 
item to the model's setSelectedItem() method.  The default editor always 
returns entered text as a string, so setSelectedItem() is been passed a 
string.  That's why you see them.

What you need to do is to map these strings to the corresponding 
ObjectX.  You can do it in one of two places:

1.  Inside EditorComponent's getItem()  (you will need to create a custom 
EditorComponet)
2.  Inside your model's setSelectedItem

Hope this helps

Dmitry

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to