views:

32

answers:

2

I have a Swing JComboBox with an InputVerifier set correctly.

I am using the combo box to set an integer.

If I type "cat" in the field and hit tab, my InputVerifier triggers and resets the value to "0".

If I type "cat" and hit enter, my InputVerifier is never called from actionPerformed. Do I need to explicitly call my InputVerifier from actionPerformed?

What's the best model to validate my JComboBox on tab and enter? It seems like this is something that should be given to me "for free" by the swing model.

+1  A: 

This is the expected behavior of InputVerifier: the TAB key attempts to change focus, while the ENTER key does not. You can bind the ENTER key to a different action, as described in the tutorial How to Use Key Bindings. Also, consider the informative article Key Bindings, which includes a handy utility application.

trashgod
+1  A: 

When using an editable combo box, focus is on a JTextField which is used as the editor of the combo box. You can add an ActionListener to this text field.

In the ActionListener you could try invoking the transferFocus() method which should be equivalent to tabbing our of the text field. If that doesn't work then tha actionListener should invoke the same editing code as the InputVerifier.

camickr