Allain Lalonde Allain Lalonde - 13 days ago 8
Java Question

How do I get InputVerifier to work with an editable JComboBox

I've got an

JComboBox
with a custom
inputVerifyer
set to limit MaxLength when it's set to editable.

The verify method never seems to get called.

The same verifyer gets invoked on a
JTextField
fine.

What might I be doing wrong?

Answer

I found a workaround. I thought I'd let the next person with this problem know about.

Basically. Instead of setting the inputVerifier on the ComboBox you set it to it's "Editor Component".

JComboBox combo = new JComboBox();
JTextField tf = (JTextField)(combo.getEditor().getEditorComponent());
tf.setInputVerifier(verifyer);