Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 517
Allain Lalonde Avatar asked Nov 05 '25 15:11

Allain Lalonde


1 Answers

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);
like image 166
Allain Lalonde Avatar answered Nov 07 '25 06:11

Allain Lalonde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!