Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How will I create a common key listener?

 
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
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!