Solved

jComboBox + Press Enter

Posted on 2003-11-11
13
613 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 47
iterator/ListIterator approach 17 39
java imports not found 4 19
learn programming 8 30
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

792 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