Solved

jComboBox + Press Enter

Posted on 2003-11-11
13
611 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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
 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

776 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