Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList enter key advice needed

 
J Roxas
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic