Click to See Complete Forum and Search --> : JComboBox keyListener


mjpell
February 22nd, 2000, 10:25 AM
I want to make a JComboBox editable. Easy enough. Now I want to add a keyListener so I can validate the user's input as he/she keys in text.
However, the keyTyped event never gets called.

I'm using the VCE in VA/Java 3.0 with JDK1.2.2. I set up the keyTyped event in the VCE. But the method never gets called.

Any suggestions as to why this doesn't get called? Or how I can trap the keyTyped event?
thanks,

poochi
February 22nd, 2000, 12:52 PM
Get editor component and add KeyListener to it.

March 1st, 2000, 01:15 PM
PLease could you (or someone) explain this in better detail...

"editor" component?

Thanks + this is a good question..

poochi
March 1st, 2000, 04:49 PM
Hi ,

JComboBox has an "Editor"( not a component , javax.swing.plaf.basic.BasicComboBoxEditor )
which is a wrapper around the actual Editor "Component" ( which is JTextField ). To get this
JTextField , first you have to get the "Editor" and then get the actual "Component".


JTextField editorcomp = comboBox.getEditor().getEditorComponent();