Catching a KeyEvent from the TAB key...

Well it does not appear to send any KeyEvents to my KeyListener...
any reason for this? and is there any fix to do?
I need a special tab completion feature for my application and need to catch the KeyEvent for the tab key.

It has to do with the focus-model. In this case both, ALT-events and TAB-events are send, but not if they are pressed together. The reason is that when they are pressed together the focus traverses to the next window (on win98 it does).
public static void main(String[] args){
  JFrame f = new JFrame("Parent"); 
  KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(createKeyEventDispatcher());
  f.setBounds(100,100,400,300);
  f.setVisible(true);
public static KeyEventDispatcher createKeyEventDispatcher(){
  return new KeyEventDispatcher(){
             public boolean dispatchKeyEvent(KeyEvent e){
            System.out.println("Dispatching: " +e);
            if(e.getKeyCode() == KeyEvent.VK_TAB){
                   //do anything
                   return true;  //Don't continue dispatching
                  }else
                   return false; //continue dispatching
}

Similar Messages

  • Why i am unable to catch the 'TAB' key press?

    hi
    i have an application where i have 2 text fields and one button in order say t1, t2 and b1.
    on tabbing t1 cursor moves to t2 and on tabbing t2 cursor moves to b1 and on tabbing b1 cursor moves to t1.
    now when i press tab button on any of the component i have written a keyListener for that to catch 'TAB' key using the comparision
    if( e.getKeyCode() == KeyEvent.VK_TAB )
    but its not catching the tab key pressed on any of these 3 components....
    why like this...
    i want to catch the press of 'TAB' key and write some action for it... but unable to catch the 'TAB' key press.
    anyone could help me in this....
    thanx in advance,
    -Soni

    I seem to remember this question being asked before. I think the answer was that the FocusManager intercepts the TAB key. I don't remember the solution but you can try searching the forum.

  • Why does the "TAB" key no longer work to move the cursor from field to field with Firefox 17 in MAC OS 10.8?

    The "TAB" key will not move the cursor from field to field with Firefox 17 in MAC OS 10.8. You have to use the mouse to click on the new field to move the cursor.

    See:
    * http://kb.mozillazine.org/accessibility.tabfocus
    Note: In OS X (as of 2005-01), if this preference is not explicitly set, the “Full Keyboard Access” setting in System Preferences will be honored. All builds before that date (e.g., Firefox 1.0.x) will ignore that setting.
    This pref doesn't exist by default, so if you want to use it instead of the system settings then you need to create a new Integer pref with the name accessibility.tabfocus and set the value to what you want (7 is to tab through all the fields).

  • KeyEvents with the TAB Key

    Hey All,
    I have a small progam with a small problem. My program is an applet with numerous textfields and I have implemented the KeyEvents event listener. What I want to have happened when I press the "Tab Key" is the cursor move from one tab to another, but when it goes to the next tab it clears out the text that is currently in the textfield. Take a look at my code segment that is giving me the problem.
    public void keyPressed(KeyEvent e)
    if(NameField == e.getSource())
              if(e.getKeyCode() == KeyEvent.VK_TAB)
                   SalaryField.setText(" ");
    I know that is works if I replace "VK_TAB" with something else like "VK_A". "NameField" and "SalaryField" are the names of mt textfields. I am currently using Java SDK 1.3.1 to program in java program, but my browser uses JVM/Runtime Enviornment 1.4.1. When I run it with my broswer nothing happens when I press tab and some for the program that I am using to progam in. I did a search in the forum and came up with I have above, but still cannot it to work. When I read APIs on 1.4.1 and 1.3.1 that both said that
    "Aside from those keys that are defined by the Java language (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_ constants. Sun reserves the right to change these values as needed to accomodate a wider range of keyboards in the future."
    What is going on? How can I solve this problem?
    Thanks,
    Iceman
    PS:
    My Interface is swing

    Hey All,
    Thanks for the help I got to work when I ran it with my programming program, but when I run it in a browser using the current JVM the tab key does not work. What is wrong now? Or how am I to use FocusListener now, I tried to use the getOppositeComponent(, my complier says that it is not a method of FocusListener. Even though java says in the docmentation that it is. Can I get some more help here. The questions again is How can I tab in a applet?
    Later,
    Iceman

  • Detecting the TAB key

    With a recent release of Java, a KeyListener no longer detects the TAB key, which is now apparently considered to be a focus event, not a keyboard event. It is critical to our application, a terminal emulator, that we be able to detect TAB and SHIFT-TAB. I read somewhere about a work-around involving a FocusListener, but a FocusListener does not report when the TAB key is pressed. Can somebody help me here?

    I seem to have solved the problem, and I'd like to present my solution in case anybody else runs across the problem.
    We use an AWTEventlistener. This is intended to watch AWT events but not handle them. However, there is no reason why we shouldn't process tab events within it. AWT will continue to process the tab key as a focus switch, but this solution enabled us to get our applet working again. I hope that future releases of Java will pay more attention to backward compatibility however, so that this kind of fix is not needed.
    In the canvas class:
    // Add the event listener provided we are on a version of the VM
    // that supports it.
    try {
    if (Class.forName("java.awt.event.AWTEventListener")!= null) {
         Toolkit.getDefaultToolkit().addAWTEventListener(new Myeventlistener(), AWTEvent.KEY_EVENT_MASK);
    } catch (Throwable e) {}
    import java.awt.*;
    import java.awt.event.*;
    public class Myeventlistener implements AWTEventListener
    public void eventDispatched(AWTEvent e)
    KeyEvent k = (KeyEvent) e;
    if (k.getID() == k.KEY_PRESSED) {
    if (k.getKeyCode() == 9) {
    if (k.isShiftDown())
    // Process as BackTab Key
    else
    // Process as tab Key

  • Using the tab key in a list and keeping a table format when copying and pas

    when I transfer a table from a microsoft word document or PDF file to the pages document, it does not keep the table and only the data inside the table. how do I keep the table?
    Also, how do I keep the numbers from indenting when I do a list. for example, if I need to indent part of the sentence for writing specifications of something, I want to use the tab key to move away from the first part of the sentence, but it moves everything and not just my marker.

    Not if it decides the list is a list, it can't.
    The app never "decide that a list is alist". It does what you ask it to do.
    Of course, if you refuse to disable the preference which automatically treats a paragraph as a new list entry I can't help you.
    If the datas are stored as a list, the bullets are not part of the datas themselves so they will not be copied.
    As I already responded the "Copy" tool doesn't copy attributes.
    We have to choose:
    we are using lists and the bullets can't be copied
    or
    we are using text arranged in columns and, if we put bullets, these bullets may be copied.
    It's not me which wrote:
    +In Textedit, it's very easy:+
    +Tab, Bullet, First Column, Tab (or Tab x2 to get everything aligned), Second Column, etc.+
    To do the same thing in Pages
    Bullet, Tab, First Column, Tab (or Tab x2 to get everything aligned), Second Column, etc.
    It's what was displayed in my screenshot and really I don't see what is more complicated.

  • Why can't I use the tab key to highlight links on a webpage?

    In previous versions of FF and in other browsers, I can use the tab key to navigate through all the links on a webpage - I can't seem to do this with FF5, the tab key will only highlight the address bar, search bar, and any form fields within a webpage.
    Using the tab key to navigate through links on a page is an accessibility feature, and I often use it to show hidden skip links at the top of a webpage for users who prefer to use the keyboard over a mouse and for assistive technologies.
    Is this something that can be turned back on in preferences? Or is there a reason why it was removed from this version?

    It can be fixed in Mac OS X Tiger preferences (Keyboard -> "all controls") or try a ctr-F7

  • What's with the tab key in the new version of Pages

    In the previous version I could have a list and was able to tab within a line in that list and it would recognize the tabs. Now, if you are in line, shifts the position of the list level.
    Version 2
    1. My list line could tab to here $50.00
    2. Second line
    3. and so on.
    Version 3
    a. My list line (shifts the list if you click the tab key) can't add anything
    2. Second line
    3. and so on.
    NOTE: the a. line under version 3 is indented when the tab key is clicked. If I do this in this reply box, this line won't even show up. That's why I edited my post.
    Or do I have something buggy when shifting from 2 to 3. (I already threw 2 away.)
    Message was edited by: darrenv
    Message was edited by: darrenv

    The fn key is on the portables, not the stand-alone keyboards. It allows for a smaller/less keys keyboard & still lets you do things like forward delete by holding down the fn key & pressing delete.

  • How to recognize the tab key in a JTextField

    I have a drawing program with a main window and a tools palette, which is a JDialog. The tools palette has JToggleButtons and one JTextField. When you have the focus in the JTextField and you press tab repeatedly, it tabs through all the JToggleButtons and then back into the JTextField.
    However I would like to recognize the pressing of the tab key and ask for the focus to go back to the main window.
    I subclassed the JTextField, added a KeyAdapter, but it does not recognize the tab key. I also added the processKeyBinding method, but it doesn't recognize the tab key either.
    How can I recognize the tab key?
    Here is a self-contained test program that illustrates the problem:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class AnanyaCurves extends JFrame
      Tools tools;
      public AnanyaCurves(Dimension windowSize)
        Basics.ananyaCurves = this;
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        setTitle("Ananya Curves");
        tools = new Tools(this);
      public static void main(String[] args)
        int toolsWidth;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        toolsWidth = 200;
        Dimension windowSize = new Dimension(screenSize.width - toolsWidth, screenSize.height - 58);
        AnanyaCurves ananyaCurves = new AnanyaCurves(windowSize);
        ananyaCurves.pack();
        ananyaCurves.setBounds(toolsWidth, 0, windowSize.width, windowSize.height);
        ananyaCurves.setVisible(true);
        ananyaCurves.requestFocus();
      public void setVisible(boolean b)
        tools.setVisible(b);
        super.setVisible(b);
    class Basics extends java.lang.Object
      public static AnanyaCurves ananyaCurves;
      public Basics()
    class Tools extends JDialog
      JToggleButton btnGrid;
      JTextField textGrid;
      JPanel panel;
      public Tools(JFrame frame)
        super(frame, "Tools", false);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        btnGrid = makeBtn("Grid");
        textGrid = makeTextField();
        panel = makePanel();
        pack();
      public JToggleButton makeBtn(String name)
        JToggleButton btn = new JToggleButton();
        btn.setMaximumSize(new Dimension(108, 24));
        btn.setPreferredSize(new Dimension(108, 24));
        btn.setText(name);
        btn.setFont(new Font("Verdana", Font.PLAIN, 11));
        btn.setMargin(new Insets(5, 10, 5, 10));
        btn.setOpaque(true);
        return btn;
      public ACJTextField makeTextField()
        ACJTextField textField = new ACJTextField();
        textField.setFont(new Font("Verdana", Font.PLAIN, 12));
        textField.setMaximumSize(new Dimension(108, 20));
        textField.setPreferredSize(new Dimension(108, 20));
        textField.setText("0.25");
        textField.setEnabled(true);
        return textField;
      public JPanel makePanel()
        JPanel panel = new JPanel();
        panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        panel.add(btnGrid);
        panel.add(textGrid);
        getContentPane().add(panel);
        return panel;
    class ACJTextField extends JTextField
      KeyAdaption keyAdaption;
      public ACJTextField()
        super();
        keyAdaption = new KeyAdaption();
        this.addKeyListener(keyAdaption);
      class KeyAdaption extends KeyAdapter
        public void keyPressed(KeyEvent event)
          int keyCode = event.getKeyCode();
          if (keyCode == KeyEvent.VK_TAB)
            Basics.ananyaCurves.requestFocus();
      protected boolean processKeyBinding(KeyStroke keyStroke, KeyEvent keyEvent, int int2, boolean boolean3)
        int keyCode = keyEvent.getKeyCode();
        if (keyCode == KeyEvent.VK_TAB)
          Basics.ananyaCurves.requestFocus();
          return false;
        return super.processKeyBinding(keyStroke, keyEvent, int2, boolean3);
    }Thanks for looking at this.

    Wow, Michael, you work like magic! Thanks so much! I would be happy to give you a commercial key to my Ananya Curves program also once the second release is on my website. It's a program for drawing curves in an easier way without pulling on tangent lines, with all control points right on the curve. Just send me an email to [email protected] if you are interested!

  • Not able to use the Tab key to Tab indent when within a text edit window...

    Two questions please... First one is above for the tab function. In Safari I just need to press control+option+tab to indent a tab within a text edit box on a website. This function is being used more via cloud and mobile capability.
    Second... I can, in Safari, Copy and paste a site with tables. Works great in Safari. When I try to do this in FF I lose the formatting of the tables and it just give plain text without the tabled fields.
    I would love to use FF because the compatibility if much greater than Safari, but... I need my functionality as well to do my work to the best and quickest ability.
    Thank you

    Help About says I'm on 20.0.1
    Up until last week, I was able to use the tab key when typing emails and other multi-line text boxes.
    Suddenly the behavior of the tab key changed. This isn't the first time. It's been quite a while ago that the function of the tab key changed from indenting to moving around the page, then after some time it changed back to indenting.
    Can we get this fixed and leave it alone, please?
    I may give one of those add-ins a try, but my problem with add-ins is that they break when FF is patched or upgraded, then I'm left with out the solution they provide.
    Can we just fix Firefox, please?
    Thanks,
    Frank
    P.S. Another potential fix I came across suggested starting FF in safe mode to see if the problem goes away. It does not. It seems to be a change to FF that appeared after an update last week. On or just befor 24 Apr.

  • Moowing focus with the tab key (swing)

    Hi. I have a JFrame with 4 text areas in. I want to be able to "hop" to the next text area by pressing the tab key. Most internet pages says this is default, but when I press tab, I get a tab space inside the text area I'm in.. Any ideas on how to do this? (i use Java 1.5)

    HashSet focusForward = new HashSet();
    HashSet focusBackward = new HashSet();
    focusForward.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0));
    focusBackward.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,InputEvent.SHIFT_DOWN_MASK));
        myTextArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,focusForward);
    myTextArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,focusBackward);

  • Why do I have to use the tab key even more to tab between page elements.

    Firefox versions prior to ver 4 I used the tab key to tab between page elements (form elements, buttons, etc). I upgraded to ver 4 and now when I tab from form element to form element I first see a gray line outlining the element area and then another press of the tab the element becomes active for me to use. I now have to use double the tab keys to move between form elements.

    Hello new_mac_user, see if the next works
    # In the [[Location bar autocomplete|Location bar]], type '''about:config''' and press '''Enter'''. The about:config "''This might void your warranty!''" warning page may appear.
    # Click '''I'll be careful, I promise!''', to continue to the about:config page.
    # in search field type (or copy/paste from here) '''accessibility.tabfocus'''
    # double-click on it and change the value to '''4''' (probably you have 1 the default on mac)
    # click ok, exit firefox and restart it.
    with the above you give focus to links (and linked images) only when you press the tab key.
    see for more info : http://kb.mozillazine.org/Accessibility.tabfocus
    https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference/accessibility.tabfocus
    thank you

  • Full screen mode and the tab key: how to ignore invisible UI elements

    Hi there,
    When Mozilla is in windowed mode, the tab key moves between the page content, which is great. However, when it reaches the end of the page, it then goes to the tab bar, the address bar, the search bar, something I can't figure out, and only then back to the page content.
    When Mozilla is in full screen mode, it does the same thing, even though none of the UI elements (such as the menu bar et al) are actually visible.
    So my question is this: is there a way to disable tab from going to the UI elements when FF is in full screen mode? If not, is there a way to disable this entirely?

    You have to change the cursor focus.
    What I usually do for PDF pages/tabs, is click in the URL/location bar, then F11.<br />
    For Flash, if you click on the page outside of the video area/box, F11 should work.

  • Strange behavior with the tab key and multiple users

    Hello,
    I'm stuck on this problem and none of the usual trouble-shooting techniques have yielded results, so perhaps someone will point me the right direction.
    I have an Intel iMac running 10.3.9 with two user accounts, and in one of the accounts the tab key fails to advance the cursor from field to field in any application, be it a browser, mail client, etc. The tab key works otherwise, I can switch between applications using apple tab, for instance. The other user account works fine. The keyboard & Mouse preferences are identical on both user accounts. In fact, after creating a new user account it too had no tabbing from field to field either, which would seem to indicate that it is not a problem in an individual account. Repairing the permissions did not help, and even a recent archive and install failed to change this. Anyone know where to look for an answer? Thanks in advance...
    iMac 2GHz Intel Core 2 Duo Mac OS X (10.4.9)

    I did a wholesale replacement of the preferences folder from the working account to the non-working one, and after going through the welcome screens and re-setting a variety of preferences (setting up mail.app again, etc...), the tab key is functioning as expected in all applications. Thanks!

  • Accessibility, exclude UI elements from the Tab-chain

    Hi,
    I have a complex UI which is very uncomfortable to access with the Tab key when using sap-accesssibility=true parameter. The main problem are the many transparent containers, which are necessary to create the refined composition of the UI. They get focused when the Tab key is pressed and this is completely useless. I there a way to exclude UI elements from the Tab-chain?
    Best regards,
    Krasimir

    Hi,
    I have same prolem here.
    In my UI I am using mastercolumn for expand /collapse functionality in parent - child node .
    The problem is the keyboard tab-chain is skipping the master column which makes it a accessibility issue.
    Is there any way we can include/exclude UI elements from tab chain.
    My NWDS version is 7.0.10.

Maybe you are looking for