• Post Reply Bookmark Topic Watch Topic
  • New Topic

KeyEvent TAB  RSS feed

 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have written the following code in order to have a tab event for the JTextField but when I press in the JTextField, there is no event. I have the same code to listener the "F9" event, it was working properly. Does anyone know what is the problem?



Thanks!
Jack
[ October 22, 2007: Message edited by: Jack Lau ]
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unlike text areas, text fields don't accept tab and enter as input characters. Instead, enter will trigger an ActionEvent and tab will cause the control to loose focus, triggering a FocusEvent. You can use ActionListener and FocusListener (or FocusAdapter) for listening to those events.
 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the AbstractAction implements the ActionListener interface.
[ October 22, 2007: Message edited by: Jack Lau ]
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it can catch the enter, but it still cannot catch the tab.
 
Jack Lau
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I put the MyTextField inside JTable, and MyTextField with the code segment of AbstractAction above, the "TAB" event can be catch and I found some print out come from actionPerformed. However, I put the MyTextField in JPanel, the MyTextField doesn't work with the "TAB" event.
[ October 22, 2007: Message edited by: Jack Lau ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!