Solved

jComboBox + Press Enter

Posted on 2003-11-11
13
607 Views
Last Modified: 2006-11-17
I have an jCombobox and I want to do something if the jcombobox is in focus and the user press Enter. I have already implemented ActionPerformed listener for the jComboBox. When I add KeyListener to that JCombobox, I found that the jcombobox run the actionperform listner instead of the key event listener. would somebody tell me how to solve this problem ?
0
Comment
Question by:mikekwok
  • 6
  • 6
13 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 9720786
Out of interest, why are you interested in the KeyListener, if it's the enter key you're interested in? What's wrong with actionPerformed?
0
 

Author Comment

by:mikekwok
ID: 9720849
how can i check if the keyevent e is "vk_enter" in the actionperformed ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9720971
That's the only key event the actionPerformed will recognise anyway, so you don't need to check.
0
 

Author Comment

by:mikekwok
ID: 9720986
it is actionevent pass into the void but not keyevent, how can i check the keystroke is enter?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9721003
The only key stroke that will be recognised is the enter key. If getSource() returns the combo box, then the enter key was pressed. AFAIK the combo box doesn't generate ActionEvents otherwise.
0
 

Author Comment

by:mikekwok
ID: 9864983
I found that the only key stroke that will be recongised is not only the enter key. It also recongnises the up arrow and down arrow. WOuld somebody pls help me ?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mikekwok
ID: 9864996
Do i need to use processKeyEvent to handle my situation ?
0
 

Author Comment

by:mikekwok
ID: 9894880
How can i distinguish between the ENTER key and other key which is pressed when jcombobox in focus ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9895715
PLease specify your *exact* requirements and i'll try to help
0
 

Author Comment

by:mikekwok
ID: 9901056
I have a jcombobox, i have implemented actionperformed, it will do  string manipution when the jcombobox changed. i also want it to do another thing when jcombobox is in focus and user press ENTER. the problem is that the actionperformed recognize BOTH the jcombobox changed and ENTER is pressed. Do I explain my problem more clear ? Look for your reply. Thanks.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 10049962
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[deleted and points refunded]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10051679
I'm happy to look into this further if the questioner's still interested
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11141484
8-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now