posted 23 years ago
Yes, there is a lower-level method that dispatches, not consumes, all events generated from a component and sends the events to the appropriate listener for that component.
You need to subclass JTextField and override processKeyEvent(KeyEvent key). Any type of key event generated from this component, this method will dispatch the event to all of this components key listeners, so there must be some special processing that blocks the TAB key, no problem thought, since we can override the method and perform our own processing, and then call super.processKeyEvent(KeyEvent) to handle all other key events other than TAB.
I just tested this code to catch the TAB key and it works, good luck.
class CustomTextField extends JTextField {
public CustomTextField( int c){
super(c);
}
protected void processKeyEvent(KeyEvent ke){
if( ke.getKeyCode() == KeyEvent.VK_TAB)
System.out.println("TAB");
//you must call this!!
super.processKeyEvent( ke);
}
}
SAF