Tab key event not fired in JTabbedPane

Hello,
I wanted to add the functionality of moving between tabs when Ctrl+Tab is pressed like Windows tabs.
But the tab key listener event is not getting fired by pressing Tab. For all the other key pushes it is working good. It this a problem with Java? Any workarounds?
Here is the sample code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestTab extends JFrame
     public void drawGUI()
          //getContentPane().setLayout(new GridLayout(1, 1));
          JTabbedPane lTabbedPane = new JTabbedPane();
          JPanel lFirstPanel = new JPanel();
          lFirstPanel.add(new JLabel("First Panel"));;
          JPanel lSecondPanel = new JPanel();
          lSecondPanel.add(new JLabel("Second Panel"));;
          lTabbedPane.addTab("Tab1", null, lFirstPanel, "Does nothing");
          lTabbedPane.addTab("Tab1", null,lSecondPanel, "Does nothing");
          getContentPane().add(lTabbedPane);
          lTabbedPane.addKeyListener(new KeyAdapter()
               public void keyPressed(KeyEvent lKeyEvent)
                    System.out.println(lKeyEvent.getKeyText(lKeyEvent.getKeyCode()));
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     public static void main(String[] args)
          TestTab lTestTab = new TestTab();
          lTestTab.drawGUI();
          lTestTab.setSize(200, 200);
          lTestTab.setVisible(true);

The KeyPressed events for TAB and CTRL-TAB are typically consumed by the KeyboardFocusManager for component traversal. What you have to do is adjust traversal keys and add CTRL-TAB as an action of your JTabbedPane. This is usually done with the InputMap/ActionMap, not a KeyListener:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class X {
    public static void main(String[] args) {
        Set tabSet = Collections.singleton(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
        KeyStroke ctrlTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK);
        final int FORWARD = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS;
        final JTabbedPane tp = new JTabbedPane();
        //setFocusTraversalKeys to remove ctrl-tab as a forward gesture
        tp.setFocusTraversalKeys(FORWARD, tabSet);
        for (int i=0; i<6; ++i) {
            JPanel p = new JPanel(new GridLayout(0,1));
            JTextArea area = new JTextArea();
            area.setFocusTraversalKeys(FORWARD, Collections.EMPTY_SET);
            p.add(new JScrollPane(area));
            area = new JTextArea();
            area.setFocusTraversalKeys(FORWARD, Collections.EMPTY_SET);
            p.add(new JScrollPane(area));
            tp.addTab("tab " + i,p);
        //add ctrlTab as an action to move to next tab
        Action nextTab = new AbstractAction("nextTab") {
            public void actionPerformed(ActionEvent evt) {
                int idx = tp.getSelectedIndex();
                if (idx != -1) {
                    idx = (idx + 1) % tp.getTabCount();
                    tp.requestFocusInWindow();
                    tp.setSelectedIndex(idx);
        InputMap im = tp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        im.put(ctrlTab, nextTab.getValue(Action.NAME));
        tp.getActionMap().put(nextTab.getValue(Action.NAME), nextTab);
        JFrame f= new JFrame("X");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(tp);
        f.setSize(400,300);
        f.setVisible(true);
[/code[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Listening Tab Key Event On JTextField

    Hi
    i am unable to listen Tab Key Event on JTextField ....
    tField.addKeyListener(new KeyAdapter()
    public void keyPressed(KeyEvent e)
    if (e.getKeyCode()==e.VK_TAB)
    JOptionPane.showMessageDialog(null,"Tab Pressed");
    else
    JOptionPane.showMessageDialog(null,"Tab Not Pressed");
    When i pressed Tab Key then it dont come in KeyPressed Event ...Actually it go towards next FocusAble component ..
    Any help in this regard.....

    I also Checked it by using
    tField..setFocusTraversalKeysEnabled(false);
    tField.addKeyListener(new KeyAdapter()
    public void keyPressed(KeyEvent e)
    if (e.getKeyCode()==e.VK_TAB)
    JOptionPane.showMessageDialog(null,"Tab Pressed");
    else
    JOptionPane.showMessageDialog(null,"Tab Not Pressed");
    In this case each time e.getKeyCode() returns 0...
    plz help me

  • Tab key does not work

    This is very strange, please read.
    My tab key does not work. It will not move from one text field to another.
    I have checked my keyboard settings. "Full keyboard access:" is at the default "Text boxes and lists only".
    I have deleted this user and recreated the user, and with the completely new user the tab key does not work. Other users on the machine it DOES work.
    This is happening now on 3 of our 5 machines.
    Lastly, when I turn on the keyboard viewer (International/Input Menu/Keyboard viewer: it shows you what key the system thinks you are pressing when you press a key on the keyboard), it shows that when I press the tab key, the Command key is being held down instead. It's not showing that the tab key is being pressed.
    Has anyone seen this previously? Again, it's happening on 3 of our 5 machines (some users the tab key works, some users it doesn't). These are fresh user creations (no special software installed, no prefs changed, etc...)
    Thank you for any info!!!

    "Repair Disk Permissions" from Disk Utility may help.
    Also, cmd-opt-n-v (Clear NV RAM) may help as well.
    Mihalis.
    Dual G5 @ 2GHz   Mac OS X (10.4.6)  

  • [JS] Tab key event (ScriptUI)

    Hi,
    If set to 'window' or 'palette' type, a ScriptUI Window can't receive 'Tab' key events on WinXP.
    Is this the same with other OS?
    Is there a workaround?
    Thanks,
    Marc

    Here's the thread about the bug
    http://forums.adobe.com/message/2068532
    It really was and is a big problem for me and soesn't seem to be getting fixed any time soon
    Steven Bryant
    http://scriptui.com

  • Tab key is not working on my macbook pro on any app including the key combos. It has snow leopard.

    Hi All,
    I have a macbook pro with snow leopard on it. The tab key is not working now suddenly. It doesn't work on any browser or applications like word or excel. The key combos with Tab also doesn't work.
    Thanks,
    Daniel.

    I noticed the same problem started a few days ago on mac pro with logic fcp keyboard but caps lock also stopped working. I cleaned under and around the tab and caps lock keys thoroughly but no dice. If I change usb ports the keyboard is plugged into caps lock lights up briefly and if I tweak keyboard setting tabs to force it to re-recognise the keyboard the tab and caps lock functions work while I have the keyboard system panel open and attempting to "identify keyboard" but back to not functioning when I close it. There have been a few postings about this problem but haven't come across the solution yet. Any ideas...

  • WHEN-CUSTOM-ITEM-EVENT - not firing. Please Help

    Hi Grant,
    WHEN-CUSTOM-ITEM-EVENT - not firing. Please Help..
    I need a help from you.
    1) I have developed an form to browse the client machine and upload the file on server / table
    2) Registered the form in Oracle Apps 11.5.10.
    3) Currently i am able to open the File_Dialog and browse throught the clients machine
    But when ever user selects any file and says Open, i am not able to retrieve the file name. wHEN-CUSTOM-ITEM-EVENT is not
    firing. I am sure how we can invoke this CUSTOM-ITEM-EVENT.
    To devlop the form i have referred PERWSIMG.fmb - of Oracle (Apps) HRMS which uploads the employee photo in the Database.
    Hence i have used the same java code / Implementaion Class.
    Please help...
    Regards
    Sameer

    Hi Francois,
    You were right. I re-loaded the zip file and the original version works. Odd, as I don't remember ever modifying those files.
    But my original issue still remains.
    The only code I've added is this:
    Color mycolor = this.getBackground() ;
    setBackground(mycolor);to the CalendarFrame constructor. How could this be causing the trigger to not fire?
    Could it be the way I created the bean? I copied all the java files to my project, attached the libraries, created a deployment profile. Everything compiles without errors or warnings, and the jar is created without issues. The java console doesn't give any errors either.
    Thanks for all your help,
    A
    Edited by: Abigail Parmar on Mar 26, 2009 1:01 PM

  • PS2 - Tab key does not work in dialog boxes

    I am referring to the dialog boxes such as "Don't save" "Cancel" "Save" and pretty much any other dialog, the Tab key does not go through the options as it does in pretty much any software I have used.
    Is this the normal behavior in Photoshop PS2; or is there some way to 'fix' it?

    Is this the normal behavior in Photoshop PS2
    That seems unlikely, but firstly:
    How To Get Help Quickly!
    And secondly: Are Photoshop and OS fully updated and have you performed the usual trouble-shooting routines (trashing prefs by keeping command-alt-shift pressed while starting Photoshop, 3rd party plug-ins deactivation, system maintenance, font validation, etc.)?

  • Capturing the TAB key event.

    How can I capture the TAB key event?
    I am trying to use it within a JTextField to do a normal text tab operation.
    Thanks,
    D

    I want to map the Tab key to a jTextField so that when the user is editing inside the jTextField they can press the TAB key to tab over a predefined number of characters.
    Thanks,
    D

  • Tab key does not work properly in Assessment mode

    I am predominatly using Adobe Captivate for software simulations and assessment purposes. 
    I've seen similar items posted on the forums and noted this appears to be a common problem with a solution, to edit the HTM file with the code  so.addParam("seamlessTabbing", "false"); see post http://forums.adobe.com/message/5283597#5283597.
    I tried this with a file that was published without the need for SCORM compliance and it worked fine.  Once the requirement was introduced for SCORM compliance (and to publish as a Zip file), this does not work as the code is different in the HTM file.
    My file has the following code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <!-- Copyright [2012] Adobe Systems Incorporated.  All rights reserved -->
    <html lang="en">
    <head>
      <link rel="stylesheet" type="text/css" href="captivate.css" />
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Enter Billable Time - Assessment</title>
      <!-- Include external JS files -->
      <script language="JavaScript1.2" src="standard.js"    ></script>
      <script language="JavaScript1.2" src="scormdriver.js"  ></script>
      <script language="JavaScript1.2" src="SCORM_utilities.js"  ></script>
      <script language="JavaScript1.2" src="Utilities.js"   ></script>
      <script language="JavaScript1.2">
       //Register event handlers
       window.onkeypress    = CheckForDebugCommand;
       window.onload    = OnloadActivities;
       window.onbeforeunload  = Finish;
       window.onunload   = Finish;
       document.onkeypress   = CheckForDebugCommand;
      </script>
    </head>
    <body>
       <div id = "CaptivateContent">
        <noscript>
         This course requires JavaScript to be enabled in your browser.
         Please enable JavaScript, then relaunch the course.
        </noscript>
       </div>
    </body>
    </html>
    How could I edit this to disable the "seamless tabbing" referred to in the original article to make the TAB key work as intended.
    Thank you.

    This is from my e-book:
    http://www.infosemantics.com.au/troubleshoot-adobe-captivate
    Notice that the procedure for Seamless Tabbing in Cp6 with SCORM is different to that for normal non-LMS courses.
    Implementing Seamless Tabbing in Cp6
    All Captivate versions up to and including Cp6 had Seamless Tabbing active by default and set in the HTM template code. But you can still turn it off by manually inserting some code into the published HTM file as follows:
    Navigate to your published Captivate content and open the HTM file in Notepad.
    Locate the line of code in the HTM file that starts with:
    var so = new SWFObject(
    Add the following code on the next line:
    so.addParam("seamlessTabbing", "false");
    Save changes to the file and test by running your project again in the browser.  You should now be able to use the TAB key without leaving your published content.
    Adding seamless tabbing to Cp6 SCORM support files
    Seamless tabbing in Cp6 SCORM projects is a little more complex because the templates are quite different to those used for normal content.  To control seamless tabbing in SCORM content you need to make the changes to the SCORM_utilities.js file in the Captivate install directory.
    Depending on whether you’re on 32bit or 64bit, you should be able to find it at one of these locations:
    32bit:
    C:\Program Files (x86)\Adobe\Adobe Captivate 6 (32 Bit)\Templates\Publish\SCORM\Default\js
    64bit:
    C:\Program Files\Adobe\Adobe Captivate 6\Templates\Publish\SCORM\Default\js
    Open the SCORM_utilities.js file in Notepad or another suitable plain text editor. Scroll down to the end of the code until you find the following lines:
    so.addParam("quality", "high");
    so.addParam("wmode", CONFIG.WMODE);
    so.addParam("bgcolor", CONFIG.BGCOLOR);
    so.addParam("menu", "false");
    so.setAttribute("name", CONFIG.SWFOBJ_NAME);
    so.setAttribute("redirectUrl", CONFIG.REDIRECT_URL);
    so.addParam("AllowScriptAccess","always");
    so.write(CONFIG.TARGET);
    Add the so.addParam("seamlessTabbing", "false"); code to this group and save the file.
    If you are currently unable to save changes to these template files, my gut feeling would be that it must have something to do with your user permissions. E.g. you are not an Administrator for your own PC. Is that possible?

  • Double Click Event not fired for IE 11 with compatibility mode for HTML elemnt table

    Hi,
    I am facing an issue with Double click event(not getting fired on double click of mouse) for IE 11 with compatibility mode on HTML element "table" for Windows 7 64 bit machine.It runs fine on IE 10 with compatible mode with Windws 7 64  bit
    machine -- double click event.
    Can you please help to resolve the issue?
    Thanks and Regards,
    Yogesh

    Hi,
    f12>Debug tab, click the 'start' button.....(select break on all exceptions from the dropdown on the Debug tab)
    click your table and correct any errors that are listed in the Console of the developer tool.... probably you are using attachEvent I/o addEventListener. You should be using addEventListener for IE9 and higher and other web browsers.(it the w3c standard
    (recommendation).
    Post questions about html, css and scripting for website developers to the MSDN IE Web Development forum. Include with your question a link to your website or a mashup that shows the issue.
    Rob^_^

  • Key-nextrec not firing in forms 10g

    I have a code in the above trigger, but it is not firing, I have it in the block property and no other place in the form
    message('In key next rec----'); message(' ');
    IF :SYSTEM.Last_Record = 'TRUE' Then
    Null;
    Else
    next_record;
    End If;

    when-new-record-instance runs when you navigate to the next record.
    Key-Nxtrec (Nxtrec is the correct spelling) only runs when you press the key assigned to call that trigger. In my environment, it is the Shift+ Down-Arrow key, but it could be just Down-Arrow -- it all depends on what key sequence is assigned to Forms Function Number 67 in your Forms Resource file, FMRWEB.res (or fmrusw.res).
    So if the trigger runs when you press the correct keyboard key, and you issue the message but do not call the Next_Record; built-in, focus will not navigate to the next record in your running form.

  • OnRowUpdating Event not firing in my DataGrid in custom web part in my production SharePoint 2013 Foundation instance

    Hi,
    I have a custom visual web part that I've developed for SharePoint 2013 Foundation.  I am using Visual Studio 2013 to develop this web part. 
    In my visual web part I have GridView that I use to update data in a SQL 2008 R@ Server Database.  In dev and test the OnRowUpdatingEvent fires properly, but in production it does not.  I have the same version of SharePoint running on dev/test/prod. 
    The main difference between the three environments is the hardware.  Production has a much beefier sever than dev and test.  Dev and test are also virtual machines where production is.
    At first I thought my problem was cache related, and I made adjustments per this article:
    http://www.dmcinfo.com/latest-thinking/blog/id/8657/fix-sharepoint-2013-distributed-cache-timeouts
    That didn't help because the event is still not firing.  I took my test application and pointed it to the production database, and that event still fires in test but not in production. So I believe that eliminates database permission errors since I'm
    using the same credentials in both instances.
    My guess is that I need to change some settings in the production environment, but I'm not sure at this point what that might be.
    Any suggestions on what settings to look at?
    Brian
    Brian Hochgurtel
    My blog

    Try this solution :
    http://stackoverflow.com/questions/5893373/c-sharp-rowupdating-method-not-called-when-update-is-clicked-in-a-gridview

  • KEY-COMMIT not firing

    I am working on an Oracle 10g database and am using Oracle Forms Developer 10g to create forms. I have created a new 2 field table in my database:
    CREATE TABLE career_cluster
    (career_cluster_code VARCHAR2(3) NOT NULL
    ,CONSTRAINT career_cluster_pk
    PRIMARY KEY (career_cluster_code)
    USING INDEX
    TABLESPACE GALINDX
    ,career_cluster_desc VARCHAR2(30) NOT NULL
    TABLESPACE galaxy;
    I have also created a form so that users can enter data into this table. I have a career_cluster data block in my form with two items: career_cluster_code (set with a maximum length of 3 in my property palette) and career_cluster_desc (set with a maximum length of 30 in my property palette). Both items are also set in the property palettes to a char data type. In my SQL code (in the form) I always have these two items set as varchar2 with (3) and (30), respectively.
    The form opens fine when I run it, however when I click on my SAVE button my KEY-COMMIT trigger is not fired -- it jumps directly to my ON-ERROR trigger and I get an Oracle ORA-06502 error message. I don't see any inconsistencies in my data types or lengths. Below is my KEY-COMMIT code:
    DECLARE hold_item varchar2(30) := :system.cursor_item;
    hold_record varchar2(10) := :system.cursor_record;
    mess_name varchar2(80);
    mess_text varchar2(80);
    BEGIN
    go_block('career_cluster');
         if (error_code = 40202) then
              goto end_of_trigger;
         end if;
    if :system.block_status = 'CHANGED' then null;
    commit_form;
    if FORM_SUCCESS then null;
    mess_name := 'Transaction Complete';
    mess_text := 'Career Cluster(s) committed to the database';
    DISP_ALERT2(mess_text,mess_name);
    end if;
    else null;
    mess_name := 'No changes to commit';
    mess_text := 'No changes have been made to the Career Cluster Code Table';
    DISP_ALERT2(mess_text,mess_name);
    end if;
    go_item(hold_item);
    go_record(hold_record);
    <<end_of_trigger>>
    null;
    END;
    I put in a DISP_ALERT message right after the BEGIN statement but it never displayed so I don't think this trigger is firing. I also put a similar DISP_ALERT message in my ON-ERROR trigger and that does display, so I know it is going right to my ON-ERROR trigger. Does anyone have any ideas what might be triggering the ON-ERROR?
    Thanks,
    -NTW

    ORA-06502 is a numeric or value error string which is raised when an arithmetic, numeric, string, conversion, or constraint error occurrs. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2).
    I would suggest you to look at the columns definitions in the table and the form fields/variables data types and lengths and make sure they are same as the backend table columns.
    Also, you don't need to put NULL; after each IF ELSE conditions if you have any other statements.
    I would also suggest that you handle any errors in either exception handler of the block or in the ON-ERROR triggers.
    Try this:
    DECLARE
        hold_item varchar2(30) := :system.cursor_item;
        hold_record varchar2(10) := :system.cursor_record;
        mess_name varchar2(80);
        mess_text varchar2(80);
    BEGIN
        GO_BLOCK('career_cluster');
        IF :system.block_status = 'CHANGED' THEN
            commit_form;
            IF FORM_SUCCESS THEN
                mess_name := 'Transaction Complete';
                mess_text := 'Career Cluster(s) committed to the database';
                DISP_ALERT2(mess_text,mess_name);
            END IF;
        ELSE
            mess_name := 'No changes to commit';
            mess_text := 'No changes have been made to the Career Cluster Code Table';
            DISP_ALERT2(mess_text,mess_name);
        END IF;
        GO_RECORD(hold_record);
        GO_ITEM(hold_item);
    EXCEPTION
      WHEN OTHERS THEN  MESSAGE(TO_CHAR(ERROR_CODE)||'-'||ERROR_TEXT);
      RAISE FORM_TRIGGER_FAILURE;
    END;

  • CS Extension, Script UI and events not firing in Photoshop CS5

    Hi!
    I'm a bit confused with two technologies dealing with SWF panels. There was a technique in the previous versions of Photoshop when SWF content has been loaded into a ScriptUI Window. Is it changed? Or does it still work together with CS Extension extensions?
    I have a script that creates ScriptUI Window and then loads an SWF into it. It has a custom 'mousemove' event listener that helped to move this window around the screen. Now - in the new Photoshop CS5 (I tried 12.0.1 as well) - it seems like the 'mousemove' event is not fired for ScriptUI windows containing SWFs.
    I'm not sure, maybe it has something to do with the new SWF treament in CS5?
    If I'm wrong, then I'm sorry, if this question doesn't fall into this forum's area of expertise.
    Thank you!

    10x,
    You saved my ***!
    It actually has to include both the PHSP "AND" the PHXS host names for it to work - this is stupid!
    If I only use PHXS the extension manager is not able to install the extension, saying it cannot find a host that matches the manifest (even though my photoshop IS the extended variation, so in a sense it's more acurate manifest-wise), and if I only use the PHSP, it IS loaded but doesn't appear in the application!
    AND THERE IS NO DOCUMENTATION ON THIS PHENOMENON ANYWHERE!
    THIS IS BEYOND IRRESPONSIBLE!
    Thank you very much david, but please, as you are an adobe employee, get this message to the right people, if you can.
    I know the corporate agenda would probabely be the incentivise people to register to the 1500$ program to get the extension-builder, by keeping the alternative inconvenient, but this issue is beyond inconvenient, it's border-line cruelty!

  • Shift+Tab Key Event

    Hallo all,
    I have a big problem ;) I am having JTables and these Jtables must lose their focus when someone clicks on Shift+TAB at the (0,0) th of its cell. I tried to do it in a key event but it doesn't accept my solution. Here is a code chunk:
    AWTEvent currentEvent = EventQueue.getCurrentEvent();
    if( currentEvent instanceof KeyEvent)
            KeyEvent ke = (KeyEvent)currentEvent;
                if(ke.getSource()!=this)
                    return;
                if(rowIndex==getModel().getRowCount()-1 && columnIndex==getModel().getColumnCount()-1
                        && KeyStroke.getKeyStrokeForEvent(ke).equals(shiftTabKeyStroke)){
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();
                    return;
                }So when I compile it, it makes a return to its 0,0 th cell instead of giving focus on the previous component.

    DB means to say this.
    AWTEvent currentEvent = EventQueue.getCurrentEvent();
    if( currentEvent instanceof KeyEvent)
            KeyEvent ke = (KeyEvent)currentEvent;
                if(ke.getSource()!=this)
                    return;
                if(rowIndex==getModel().getRowCount()-1 && columnIndex==getModel().getColumnCount()-1
                        && KeyStroke.getKeyStrokeForEvent(ke).equals(shiftTabKeyStroke)){
                      SwingUtilities.invokeLater(new Runnable(){
                          public void run()
                                 KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();                         
                    return;
                }

Maybe you are looking for