Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:24:19+00:00 2026-05-24T20:24:19+00:00

I have a Swing JComboBox with an InputVerifier set correctly. I am using the

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:24:20+00:00Added an answer on May 24, 2026 at 8:24 pm

    The problem is “hit Tab” and “hit Enter” mean two different things in Java Swing. But those two actions mean the same thing to you, me, and the user.

    Swing has no single mechanism to detect “when the user is done entering data”. Instead, Swing focuses on the mechanics of “is this field losing keyboard focus” and “is the user pressing Enter key while inside a field”.

    Semantically those two actions mean the same thing from the user’s perspective: “I’m done. Here’s my input.”. But, from what I can tell, Swing fails to offer a way to detect that user intention. I’m as surprised as you by the lack of such a feature, as this seems to be the most basic function of a form in a GUI. What we need, but don’t have, is a “dataEntered” event.

    There is a workaround…

    In a similar context (JTextField instead of JComboBox) the Sun/Oracle Java Tutorial provides the example InputVerificationDemo where a class is created that:

    • Extends InputVerifier (to handle tabbing/clicking where focus is about to be lost)
    • Implements ActionListener (to handle pressing Enter key without leaving field)

    The good thing about this workaround is that you can locate your handling code all in one place. The downside is that you still have the hassle of:

    • Creating a separate class.
    • Instantiating that class.
    • Passing that instance to both the setInputVerifier and addActionListener methods of your widget (JTextField, etc.).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java Swing application, developed on Mac OS X 10.5 using Java
I have a swing application that read HTML pages using the following command String
We have a Java Swing application which contains components like JTable, JCombobox, JTextArea and
I have the following anonymous class box = new JComboBox(filename); ... box.addItemListener( new ItemListener()
I have a created a UI in swing using NetBeans. There are some use
I have a Java swing application with a panel that contains three JComboBoxe s
I have a swing gui with a tabbed pane in the north. Several key
I have a swing application that includes radio buttons on a form. I have
I have a Swing Application running under Linux, that has problems to display accented
i have a swing application that i would like to run on os x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.