This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JList  enter key advice needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList  enter key advice needed " Watch "JList  enter key advice needed " New topic
Author

JList enter key advice needed

J Roxas
Greenhorn

Joined: Aug 04, 2005
Posts: 12
Hi, everybody!

I have a jtextfield, every time F7 is pressed on this jtextfield i'm displaying a jlist. The user selects from that jlist by pressing ENTER key. To trap this event, I added a key listener to the jlist and once enter key is pressed, i'm processing the selected item and returning focus to the original jtextfield where F7 was pressed. What happening is my cursor is navigated automatically to the next jtextfield and not on the original jtextfield. What I think is that this is the result of my enter key on the jlist not being consumed and being translated as the enter key on the original jtextfield. Can anyone pls. try to analyze this scenario and advice me what to do as I am new to Java. Also pls. advice me if how im handling the enter key in jlist is correct or not.

Thanks!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i'm processing the selected item and returning focus to the original
> jtextfield where F7 was pressed

at the end of the JList processing are you calling
textField.requestFocusInWindow();

if you are, post a sample program of your code:
just a frame with 2 textfields, F7 code to display JList, and the code
where the JList closes and focus returns to the next textfield.


> advice me if how im handling the enter key in jlist is correct or not.

impossible to say without seeing the code. Normally you would use a ListSelectionListener,
but if using this you have to trap the selection from the de-selection, using
if(lse.getValueIsAdjusting() == false)//has been selected
J Roxas
Greenhorn

Joined: Aug 04, 2005
Posts: 12
Thanks for the reply, Michael.

While preparing for the code you were asking me to post, I was able to realize what went wrong with it. My requestFocusInWindow was inside a nested IF and as I traced down, it was also calling a procedure which is making another requestFocusInWindow into another jTextField that was causing the program to focus into another jTextField, it was solely my mistake, sorry for this... Now the program is working well!

Again, thank you for your reply!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList enter key advice needed
 
Similar Threads
Problem with KeyEvent and VK_TAB
Capture multiple Key Press ctrl+p?
getting result in textfield using jlist
JTextField Action on Tab key
disabling ENTER key