Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How will I create a common key listener?  RSS feed

 
J Roxas
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everybody!

I am coding a simple form which is attached to a table. My jtextfields take its values from the corresponding columns of the table. My question is how can I make a common key listener which listens to a PageUp or PageDown keypress from ANY of the jtextfields which signals that I should navigate accordingly through my resultset. What Im doing now is I attached key listeners to all those jtextfields and calls a common routine to trap those keys, which I believe can be improved.

Thanks.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this

 
J Roxas
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Michael! The code you've given me is working fine. Now, another question arises. How will I respond only to the fields which I wanted to trap those keypresses? (PageUp and PageDown). These are the fields which are mapped to my table's columns and not to other components within the frame.

Thanks.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are talking about 'all' JTextField components, and no other components



if it's not 'all' JTextFields, keyBindings might be a better option
http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!