Tab not generating keyevent

  • Thread starter George Weinberg
  • Start date
G

George Weinberg

I've got a KeyEventListener listening on a JTextField,
and for some reason the tab key isn't generating a
keyPressed event, although any other key does.
Any ideas why this should be and what I
can do about it? I'm using the 1.5 jdk, and by the way
the JTextField is the only component on the JFrame that
takes focus.

George
 
O

Owen Jacobson

I've got a KeyEventListener listening on a JTextField,
and for some reason the tab key isn't generating a
keyPressed event, although any other key does.
Any ideas why this should be and what I
can do about it? I'm using the 1.5 jdk, and by the way
the JTextField is the only component on the JFrame that
takes focus.

Just at a guess, but perhaps some other event handler, internal to Swing,
is intercepting 'Tab' events to handle focus change. Try installing your
KeyEventListener higher up in the containment heirarchy.
 
B

Babu Kalakrishnan

George said:
I've got a KeyEventListener listening on a JTextField,
and for some reason the tab key isn't generating a
keyPressed event, although any other key does.
Any ideas why this should be and what I
can do about it? I'm using the 1.5 jdk, and by the way
the JTextField is the only component on the JFrame that
takes focus.

The Tab key is used by the KeyboardFocusManager as a focus traversal key
and therefore will not be passed on to the component. If you want to use
Tab within the JTextField, you will need to define a different set of
keys (which excludes the Tab key) for the component's focus traversal
keys set. Look at the API docs for the method setFocusTraversalKeys(int
,Set) of the java.awt.Component class, and the documentation for the
java.awt.KeyboardFocusManager class in general.

BK
 
T

Tor Iver Wilhelmsen

George Weinberg said:
I've got a KeyEventListener listening on a JTextField,
and for some reason the tab key isn't generating a
keyPressed event, although any other key does.
Any ideas why this should be and what I
can do about it?

theJTextfield.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,Collections.EMPTY_SET);
theJTextfield.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,Collections.EMPTY_SET);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top