Results 1 to 6 of 6
Thread: Cannot Listen TAB key
- 07-15-2009, 08:45 PM #1
Cannot Listen TAB key
Hello
I have JTextField which has KeyListener associated.
I can't understand why the TAB key is not captured with this KeyListener.
Here is my code.
I have already tried change toJava Code:public void keyPressed(KeyEvent key) { if(key.getKeyCode() == KeyEvent.VK_TAB) System.out.println("TAB!!!!!!!!!"); } public void keyTyped(KeyEvent key) { if(key.getKeyCode() == KeyEvent.VK_TAB) System.out.println("TAB!!!!!!!!!"); } public void keyReleased(KeyEvent key) { if(key.getKeyCode() == KeyEvent.VK_TAB) System.out.println("TAB!!!!!!!!!"); }
<MyJTextField Component>.setFocusTraversalKeysEnabled(true);
<MyJTextField Component>.setFocusTraversalKeysEnabled(false);
without success, and the strange think is when I press CTRL+TAB, the TAB Key is capured.
Thank you!
Any help will be appreciated.Last edited by sh4dyPT; 07-15-2009 at 09:07 PM.
Ubuntu, Linux for human Beings!
- 07-15-2009, 11:18 PM #2
The forum software will not accept the code I want to post to demonstrate what is happening with respect to the tab key. A key binding for the tab key is being used as a focusTraversalKey by the textField or an ancestor container.
I'll try for some selected snippets:
Java Code:// intercept all keyboard input KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.addKeyEventDispatcher(new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_TAB) System.out.println("TAB!!!!!!!!!"); return false; } });Java Code:private void exploreTraversalKeys(JComponent jc) { Set keys = jc.getFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); Iterator it = keys.iterator(); while(it.hasNext()) { System.out.println(it.next()); } }Java Code:JTextField textField = new JTextField(12); JPanel panel = new JPanel(); panel.add(textField); // Look for a key binding of the tab key that might be // consuming the KeyEvent generated by the tab key // being pressed when the cursor is in textArea. // this method won't pass forum software filters // exploreKeyBindings(textField); exploreTraversalKeys(textField); // found return panel; }
-
- 07-16-2009, 02:01 AM #4
create a JAR with source files, change the extension to .zip, and post the zip file
I'll try it. Thanks.
- 07-16-2009, 12:05 PM #5
This is exactly what I was looking for. Thank you very much
Ubuntu, Linux for human Beings!
- 07-16-2009, 01:45 PM #6
Similar Threads
-
java.net.SocketException: Permission denied: listen failed
By vitaliy in forum NetworkingReplies: 3Last Post: 05-22-2011, 03:16 PM -
how to listen for buttons between jpanels?
By pjr5043 in forum New To JavaReplies: 17Last Post: 09-29-2008, 03:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks