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 8370009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:48:19+00:00 2026-06-09T13:48:19+00:00

Of what use is this API? I adopted it a few months ago with

  • 0

Of what use is this API?

I adopted it a few months ago with the thought in mind that I could use it to trap both keyboard and mouse actions in a ComboBox to invoke business logic once the user made a selection. As a developer, I went along, using the mouse only, blissfully ignorant, thinking my solution good, until the tester got involved and actually tried to use the combo box with the keyboard. It seems that itemStateChanged() has a very counter-intuitive (to me anyway) sense of what it means to change the item state.

When used with a mouse, the user can move over the droplist, with the mouse, with the droplist highlighting the combo box entry that currently contains the mouse cursor but without generating the event. The event is generated when the user actually clicks on an item. This is very intuitive and what I would expect.

On the other hand, with the keyboard, every press of the down-arrow causes an itemStateChanged event to be generated. This is counter-intuitive and not what I want. I want to generate an event only when the user singals his choice by pressing the Enter key signalling that the choice has been made – i.e. the analogue of the mouse click, not of the mouse move. Is there a way to make the combo box behave in this way or can I not use itemStateChanged for trapping these events?

I should add, also, that the ItemEvent itself contains nothing that would help me disambiguate the situation.

Update: OK, this is the nub of the issue: How can I make Swing treat down-arrowing through the drop list of a combo box as the equivalent of moving the mouse through the elements of the drop list? Both ItemListener and ActionListener consider the arrow-key action a “selection” rather than a navigation. Whereas I want the keyboard to be analogous to the mouse. Our requirement is to make everything work with the keyboard. The mouse is a nice-to-have that experienced users of this application won’t use much.

  • 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-06-09T13:48:20+00:00Added an answer on June 9, 2026 at 1:48 pm

    As per the Javadoc itemStateChanged(ItemEvent e) is invoked when an item has been selected or deselected by the user. And what you see is exactly the same behavior. With your arrow keys, for each key pressed you’re effectively selecting (and also deselecting at the same time) one particular item from the combo.

    For your situation, I think you should consider implementing your business logic as part of a JButton that servers as a confirmation of user selection or try out having a FocusListener on the JComboBox and having your logic as part of public void focusLost(FocusEvent e). Here’s a tutorial to help you get a better picture for FocusListener

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an API (Twitter API does not provide this) that I can use
I want to use this api that returns the place matching a zipcode e.g.
I tried to use this snippet from the Soundcloud API: <script src=http://connect.soundcloud.com/sdk.js> <script> SC.initialize({
I am trying to use this function from a COM API which enables the
I'm using this PHP framework for use with Shopify's API Can anyone help me
I'm trying to use depedency resolver inside a Web Api method. This worked fine
I had the following HTML page rendering to use the Google Maps API. This
Let's say I want to use this API: http://hiveminder.com/help/reference/API.html The instructions walk through its
There is an API for Cisco VPN (vpnapi.dll). Is it possible to use this
I would like to use an API that is written in c++. It involves

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.