Handling keyTyped events in JTable for TAB key

In my app, I have a JTable. Some columns are non-editable.
I have attached a keyListener to the table and have overridden keyTyped() and keyReleased() methods.
In keyReleased(), I do something depending on the key code. For example: if its the VK_DELETE, I delete the row. If its some other user configured key, then I show a popup dialog where the user can enter some data, etc...
In keyTyped(), I first check if the column is one of the specific columns. Then I get the keyChar. After this, I show a dialog and pre-populate a JTextField on this dialog with that keyChar.
My issue is that 'TAB' key events arrive in keyTyped() and not in keyReleased(). As a result, the dialog is shown and the tab takes place inside the JTextfield which is incorrect.
I would like to ignore TAB keyTyped events. When I look up the keyCode in keyTyped() method, it is 0. So there is no way for me to tell what key was typed.
How can I ignore TAB events in my keyTyped() method?
thx

I now do the following to determine if TAB key has been typed
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (c == KeyEvent.VK_TAB) {
Is this correct ?
Edited by: tsc on Sep 28, 2007 12:40 PM

Similar Messages

  • Is it possible to handle multiple events using Jscript for a button in Apex

    Hi,
    I've application wherein in one of the pages for a button, I need to trigger 2 events as: 1. redirect to a new page upon 'click' of the button
    2. display a set of values on 'mouse over' that button.
    I'm able to handle both separately, but not in one button. I would like to know if there is any limitation in Apex that we cant handle multiple events? Currently I've put a text item near the button, and called the Jscript for mouse over event in that as a temporary workaround. Can someone let me know if this is feasible? If not any other alternative to handle this?
    Thanks in advance,
    gsachidh

    Hi Gsachidh,
    well interesting problem you're facinng. Indeed, it can't be specified using the 'Button Attributes' So we have to come up with an workaround.
    A quick en dirty solution would be to specify it with the 'Optional URL Redirect options'. In a normal button, with processing on same page, this would be 'no target'. but in case of additional things to be done this can be used, using an target URL. I used this many times, in example with popUp windows for refreshing the caller object when changes are made. In your case we have to add next to the href an onmouseover event. this can be done with;
    Target set to => URL
    URL - target => javascript:doSubmit('<button_name>');" onMouseOver="javascript:showTooltip('tooltip');"
    Here the " is the key, letting ApEx know the target (href) is doSubmit('<button_name>'), just like when no target would be specified and adding a new javascript event; onMouseOver.
    Although this is a dirty solution in my opinion, it is the best i could come up with. I have another idea in how to do this, that is by adding this event dynamically with javascript with an addEvent. But i don't have an example at the moment for this scenario.
    Simon
    Message was edited by:
    S1M0N

  • To trigger event or action on "TAB" key press on web dynpro view

    Hi, I need to trigger event on "TAB" key press on web dynpro view , is it possible?How?

    Hi Dipak
    What Madhu said is correct. Tab key is pre-configured to move cursor from 1 field to next field. we can not create an event on tab key press.
    Regards
    Gaurav

  • Design for mirroring keytyped events for a shared editor

    Hi there,
    Can anyone suggest a layout for an algorithm which will allow a shared editor to handle keytyped events and have that mirrored in the listening client?
    So far the received packets get added to a JEditorPane by a setText() call, but this is useless as it overwrites anything in the JEditorPane.. As every KeyTyped event is fired the packet gets sent to another client that needs to append them to the JEditorPane. But I also need to consider the Caret position, deleted text, tab and space (everything under the sun that could happen when someone is editing text in the JEditorPane).
    Has anyone got any suggestions as to how to correctly tackle this problem..
    Thanks : -)
    Adrian

    It may be possible but I still wouldn't do it that way. Mainly because key events aren't sufficient to synchronize two documents. It's possible to change a document without a keyevent occurring -- for example if you press Ctrl-V on many computers, it will paste the contents of the clipboard into the document. I don't know if you get a key event in this case, but even if you do it doesn't tell you enough to synchronize the remote document properly.

  • Unable to receive Tab key press event

    Hello,
    I have written a component which extends JComponent.
    For that , when Tab key is pressed I need to process something.
    I have overridden the function processKeyBinding in my class.
    But I am not getting any event for tab key press. For all the other key press events, the function is being called.
    I also tried to create a action and add it to the action map. But that is also not working.
    Can anyone explain me why it is not working and give me the solution.
    Thanks in advance,
    Anu

    public static void removeTabFromFocusTraverval(Component c) {
         int id = KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS;
         Set strokes = c.getFocusTraversalKeys(id);
         Set newStrokes = new HashSet(strokes);
         newStrokes.remove(KeyStroke.getKeyStroke("TAB"));
         c.setFocusTraversalKeys(id, newStrokes);
    }

  • Handling desktop events

    Is it possible in java to handle desktop events, like mouse click and key press on the main desktop window in both Windows and Linux? Can we get a handle to the main desktop window?

    thanks!
    Robot solves part of my problem. I also wanted to capture system wide events in the similar way Robot generates events.
    But this will also suffice.
    Thanks again

  • Tab inside JTable (works for any key but tab)

    Hi there
    I have looked on the internet and forums for the answer to how to do this, but I have had no solution.
    I have a JTable and the second column is full of editable cells. The requirement is that when a cell is being edited and tab is pressed, that the editor moves to the next editable cell. (In this case the one below it.)
    I can get the code to work for pressing an arbitrary key (like F11) but for tab I cannot get it to work.
    Any help would be most appreciated.
    Many kind regards,
    Rachel

    Hi Rachel,
    I did this some time ago for a small project. Please note that the code that I'm pasting is a little too specific for your goal, but you'll be able to modify it so that it works.
    public class TableKeyboardAction extends AbstractAction {
          * Constructs a TableKeyboardAction.
         public TableKeyboardAction() {
              super();
         } //end constructor
          * Deals with all keyboard focus movement caused by the TAB, SHIFT+TAB & ENTER keys.
          * @param ae The ActionEvent indicating that either TAB, SHIFT+TAB or ENTER has been
          * pressed.
          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
         public void actionPerformed(ActionEvent ae) {
              JTable table = (JTable)ae.getSource();
              String ac = ae.getActionCommand();
              boolean tab = ac.equals("\t");
              boolean enter = ac.equals("\n");
              if (tab && (ae.getModifiers() & KeyEvent.SHIFT_MASK) == KeyEvent.SHIFT_MASK) tab = false;
              int row = table.getSelectedRow();
              int col = table.getSelectedColumn();
              //if tab or enter has been pressed
              if (tab || enter) {
                   TableCellEditor tce = table.getCellEditor();
                   //if the first column
                   if (col == 1) {
                        //if the cell is currently being edited
                        if (tce != null) {
                             //if the cell can stop being edited
                             if (tce.stopCellEditing()) {
                                  if (table.isCellEditable(row, col+1)) table.changeSelection(row, col+1, false, false);
                             else {
                                  ((DoubleTableModel)table.getModel()).fireTableDataChanged();
                                  table.changeSelection(row, col, false, false);
                        else {
                             //if tab has been pressed
                             if (tab) {
                                  Double val = (Double)table.getValueAt(row, col);
                                  if (val == null) table.transferFocus();
                                  else if (table.isCellEditable(row, col+1)) table.changeSelection(row, col+1, false, false);
                   else {
                        //if the cell is currently being edited.
                        if (tce != null) {
                             //if the cell can stop being edited
                             if (tce.stopCellEditing()) {
                                  if (row == table.getModel().getRowCount()) table.transferFocus();
                                  else if (table.isCellEditable(row+1, 1)) table.changeSelection(row+1, 1, false, false);
                             else {
                                  ((DoubleTableModel)table.getModel()).fireTableDataChanged();
                                  table.changeSelection(row, col, false, false);
                        else {
                             //if tab has been pressed
                             if (tab) {
                                  if (row == table.getModel().getRowCount()) table.transferFocus();
                                  else if (table.isCellEditable(row+1, 1)) table.changeSelection(row+1, 1, false, false);
              else {
                   //if it is a tab+shift combination
                   TableCellEditor tce = table.getCellEditor();
                   //if first column
                   if (col == 1) {
                        //if the cell is being edited
                        if (tce != null) {
                             //if the cell can stop being edited
                             if (tce.stopCellEditing()) {
                                  //if it's not the first row in the table
                                  if (row != 0) {
                                       if (table.isCellEditable(row-1, col+1))     table.changeSelection(row-1, col+1, false, false);
                             else {
                                  ((DoubleTableModel)table.getModel()).fireTableDataChanged();
                                  table.changeSelection(row, col, false, false);
                        else {
                             //if it's not the first row in the table
                             if (row != 0) {
                                  if (table.isCellEditable(row-1, col+1))     table.changeSelection(row-1, col+1, false, false);
                             else table.transferFocusBackward();
                   else {
                        //if the cell is being edited
                        if (tce != null) {
                             //if the cell can stop being edited
                             if (tce.stopCellEditing()) {
                                  if (table.isCellEditable(row, col-1)) table.changeSelection(row, col-1, false, false);
                             else {
                                  ((DoubleTableModel)table.getModel()).fireTableDataChanged();
                                  table.changeSelection(row, col, false, false);
                        else {
                             if (table.isCellEditable(row, col-1)) table.changeSelection(row, col-1, false, false);
         } //end actionPerformed
    } //end class
    Now use it like so:
    JTable table = new JTable();
    table.getInputMap(JTable.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "next");
    table.getInputMap(JTable.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK),"next");
    table.getActionMap().put("next", new TableKeyboardAction());Hope it works for you!
    -Muel

  • Tab key selects cell for edit in JTable

    Hello,
    I've seen extensive posts on this forum for this problem, but no solution yet.
    I have a Jtable, with custom cellRenders and cellEditors. Some columns are editable, some are not.
    What I want to do, is when someone tabs to an editable cell, that cell immediately goes into edit mode. This means, it acts as if someone double clicked on it, or tabbed then clicked on it. Basically, I want it to ACTUALLY go into edit mode.
    Please do not respond by telling me how to make it look editable (highlighting, etc) and do not respond with mouseEvent solutions. Please do not respond by telling me to do table.editCellAt(row,col) because that does not kick in my custom editor, it uses the defaultCellEditor.
    So basic question:
    How to kick in editing when someone tabs to an editable cell?
    If you need code examples, please request and I will post.

    nmstaat,
    In JTable:
    Look into the processKeyBinding method. It takes a keyevent and matchs it with an InputMap, and the InputMap invokes an Action in the corresponding ActionMap.
    You will have to call yourJTable.getActionMap(), then alter the action that corresponds to the 'tab' key.
    For Further information, check the JTable API, its all there.
    Good Luck,
    Alex
    Here's the current map for the Metal look and feel:
    JTable (Java L&F)
    Navigate out forward | Tab
    Navigate out forward | Ctrl+Tab
    Navigate out backward | Shift+Tab
    Navigate out backward | Ctrl+Shift+Tab
    Move to next cell | Tab
    Move to next cell | Right Arrow
    Move to previous cell | Shift+Tab
    Move to previous cell | Left Arrow
    Wrap to next row | Tab
    Wrap to next row | Right Arrow
    Wrap to previous row | Shift+Tab or Left
    Wrap to previous row | Shift+Tab or Left
    Block move vertical | PgUp, PgDn
    Block move left | Ctrl+PgUp
    Block move right | Ctrl+PgDn
    Block extend vertical | Shift+PgUp/PgDn
    Block extend left | Ctrl+Shift+PgUp
    Block extend right | Ctrl+Shift+PgDn
    Move to first cell in row | Home
    Move to last cell in row | End
    Move to first cell in table | Ctrl+Home
    Move to last cell in table | Ctrl+End
    Select all cells | Ctrl+A
    Deselect current selection | Up/Down Arrow
    Deselect current selection | Ctrl+Up/Down Arrow
    Deselect current selection | Pgup/Pgdn
    Deselect current selection | Ctrl+Pgup/Pgdn
    Deselect current selection | Home/End
    Deselect current selection | Ctrl+Home/End
    Extend selection one row | Shift+Up/Down
    Extend selection one column | Shift+Left/Right
    Extend selection to beginning/end of row | Shift+Home/End
    Extend selection to beginning/end of column | Ctrl+Shift+Home/End
    Edit cell without overriding current contents | F2
    Reset cell content prior to editing | Esc

  • JTable tab key navigation with JComboBox Cell Editors in Java 1.3 & 1.4

    Hello - this is one for the experts!
    I have a JTable which has an editable JComboBox as one of the cell editors for a particular column. Users must be able to navigate through the table using the tab key. After editing a cell a single tab should advance the cell selection to the next column and then the user should just be able to start typing to populate the cell.
    However, i've come across some really frustrating differences between the Swing implementation of JDK1.3.1_09 and JDK 1.4.2_04 which means this behaviour is very different between versions!....
    1. Editing Cells and then advancing to the next column using tab.
    Using standard cell editors (based around JTextFields) in 1.3.1 the user has to press tab twice to traverse to the next column after editing. However, in 1.4.2 a single tab key is enough to move to the next column after editing.
    2. Editable JComboBox editors and and advancing to the next column using tab.
    Using JDK 1.3.1, having entered some text in the editable combo it takes 2 tabs to transfer the selected cell to the next column. With 1.4.2 a single tab while editing the editable combo ends editing and transfers the selection out of the table completely?!?
    With these 2 issues I don't know how to make a single tab key reliably transfer to the next cell, between java versions. Can anyone please help me?!??!
    (i've attached test code below which can be run in both 1.3 and 1.4 and demonstrates the above behaviour.)
    package com.test;
    import java.awt.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TableTest4 extends JFrame {
         private JTable table;
         private DefaultTableModel tableModel;
         public TableTest4() {
              initFrame();
          * Initialises the test frame.
         public void initFrame() {
              // initialise table
              table = new JTable(10, 5);
              tableModel = (DefaultTableModel) table.getModel();
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              table.setRowHeight(22);
              JScrollPane scrollPane = new JScrollPane(table);
              getContentPane().add(scrollPane);
              JButton dummyBtn1 = new JButton("Dummy Button 1");
              JButton dummyBtn2 = new JButton("Dummy Button 2");
              // initialise frame
              JPanel btnPanel = new JPanel(new GridLayout(2, 1));
              btnPanel.add(dummyBtn1);
              btnPanel.add(dummyBtn2);
              getContentPane().add(btnPanel, BorderLayout.SOUTH);
              // set renderer of first table column to be an editable combobox
              JComboBox editableCombo = new JComboBox();
              editableCombo.setEditable(true);
              TableColumn firstColumn = table.getColumnModel().getColumn(0);
              firstColumn.setCellEditor(new DefaultCellEditor(editableCombo));
         public static void main(String[] args) {
              TableTest4 frame = new TableTest4();
              frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);

    Run the above code in 1.3 and 1.4 and you can see that after editing a cell, the tab key behaviour works differently between versions.
    I don't believe by adding a key listener to the cell editors will have the desired effect.
    I've read other posts and from what i've read it looks like the processKeyBinding method of the JTable can be overridden to manually handle key events.
    Has anyone done this to handle tab key presses so that the same java app running under 1.3 and 1.4 works in the same way ??? I would really appreciate some advice on this as its very frustrating !

  • JTable TAB key listener

    Hi all:
    I'm trying to write a filterable jtable. User can input the filter rule in the table header and the table displays the filtered data at the same time when the user inputs letters. The table filter works fine. But when I try to add "TAB" key listener, I find that I can't track the "TAB" key. I use a customerized cell renderer to display the filterable table header, a customerized cell editor to edit the filterable table header. The cell editor is created like this:
    JTextField textField = new JTextField("");
    DefaultCellEditor cellEditor = new DefaultCellEditor(textField);
    And I add a KeyListener to the textField. The KeyListener can track other keys like "Shift", "Alt", "Ctrl", but it can't track "TAB". It's weird. I also add the KeyListener to JTableHeader, JTable, but when I edit something in the JTextField, I still can't catch the "TAB" key. Have any ideas? Thank you for your time.

    by default the Tab is used (and consumed) by
    focusManager to move focus between components. If you
    want to get it in a component you have to signal the
    manager to keep it's hands off. How to do so depends
    on the jdk version. Focus handling changed
    considerably between 1.3 and 1.4: Prior to 1.4 you
    have to subclass the component in question to return
    true on isManagingFocus(), since 1.4 you have to set
    the comp's focusTraversalKeys to make the manager take
    those instead of the default keys.
    Greetings
    JeanetteThanks Jeanette, it works. I use the Component.setFocusTraversalKeysEnabled(false) to disable all traversal keys of JTextField and add a KeyEventDispatcher to the KeyboardFocusManager. It finally works. Users can use "TAB" keyStroke and "Shift-TAB" keyStroke to traverse in the filterable table header now. Thank you for your great help and the $$ are yours.

  • Listening events for numeric keys

    Hi,
    How can I listen events for numeric keys without using Canvas?
    I mean I would like to take some actions when user writes something
    on a TextField. My main class is not inherited from Canvas and because of that
    I can't use keyPressed() method to handle these numeric keys.
    Is there a way to handle these events in commandAction() method?

    Hi,
    If u r concerned only about the texfields and if you are using MIDP 2.0 compatible device then try ItemCommandListener.

  • [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 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[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Customize "Tab" key for JTextArea to focus next component.

    Hi,
    I am trying to change the "TAB" key behaviour for JTextArea, by using CustomAction configured via InputMap() and ActionMap(). When the user presses the Tab key, the focus should go the next component instead of tabbing in the same JTextArea component. Here is the code for the CustomAction().
        public static class CustomTabAction extends AbstractAction {
            private JComponent comp;
            public CustomTabAction (JComponent comp) {
                this.comp = comp;
                this.comp.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "TABPressed");
                this.comp.getActionMap().put("TABPressed", this);
            public void actionPerformed(ActionEvent evt) {
                Object source = evt.getSource();
                if (source instanceof Component) {
                    FocusManager.getCurrentKeyboardFocusManager().
                            focusNextComponent((Component) source);
        }This works for most of the cases in my applicaiton. The problem is that it doesn't work with JTable which has a custom cell editor (JTextArea). In JTextArea field of JTable, if the Tab is pressed, nothing happens and the cursor remains in the custom JTextArea exactly at the same place, without even tabbing spaces. Here is the CustomCellEditor code.
        public class DescColCellEditor extends AbstractCellEditor implements TableCellEditor {
    //prepare the component.
            JComponent comp = new JTextArea();
            public Component getTableCellEditorComponent(JTable table, Object value,
                    boolean isSelected, int rowIndex, int vColIndex) {
                // Configure Tab key to focus to next component
                CustomActions.setCustomAction("CustomTabAction", comp);
                // Configure the component with the specified value
                ((JTextArea)comp).setText((String)value);
                // Return the configured component
                return comp;
            // This method is called when editing is completed.
            // It must return the new value to be stored in the cell.
            public Object getCellEditorValue() {
                return ((JTextArea)comp).getText();
        }regards,
    nirvan

    >
    textArea.getInputMap().remove(....);but that won't work because the binding is actually defined in the parent InputMap. So I think you need to use code like:
    textArea.getInputMap().getParent().remove(...);But I'm not sure about this as I've never tried it.I tried removing the VK_TAB key from both the input map and parent input map as shown below. But I still have to press "TAB" twice in order to get out of the JTextArea column in JTable.
                comp.getInputMap().getParent().remove(
                            KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));
                comp.getInputMap().remove(
                            KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));after coding this, I am using the setFocusTraversalKeys for adding only "TAB" key as ForwardTraversalKey as given below.
            Set newForwardKeys = new HashSet();
            newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
            comp.setFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,newForwardKeys);
            Set newBackwardKeys = new HashSet();
            newBackwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK));
            comp.setFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,newBackwardKeys);The only problem that remains now is that I have to press the "TAB" twice in order to get out of the JTextArea column
    regards,
    nirvan.

  • Tab Key Navigation in JTable

    Hello All,
    Can anyone please help me with Tab key navigation in a JTable.I
    read all the messages in this group but couldn't implement one.It
    would be a great help if anyone can provide me a working example of how
    to control the tab key in the JTable. I have a JTable with some of the
    columns not editable, I want the focus to be in the first cell and
    whenever the TAB key is pressed, the focus should go to next editable
    cell and select the data in it.For example: if you take a simple table of 4 columns with column 2 not editable, The focus should begin with the first cell(1st column,1st row) and goto (3rd column,1st row) whenever TAB is pressed.It should work in reverse when SHIFT-TAB is pressed.
    I'm new to Java Swing.I would greatly appreciate if anyone can provide me a working example.
    Thanks in advance,
    siddu.

    OK Here is what I have ...
    public class MultipleEditorsPerColumnJTable extends JTable {
    /** Creates a new instance of MultipleEditorsPerColumnJTable */
    public MultipleEditorsPerColumnJTable( int the_column) {
    this.myColumn = the_column;
    this.rowEditors = new ArrayList();
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed) {
    boolean isSelected = false;
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0)) {
    int selRow = getSelectedRow();
    int rowCount = getRowCount();
    int selCol = getSelectedColumn();
    if (selCol == 1) { isSelected= getCellEditor(selRow,selCol).stopCellEditing();}
    int targetRow = (selRow + 1) % rowCount;
    this.editCellAt(targetRow, 1);
    this.getComponentAt(targetRow, 1).requestFocus();
    return super.processKeyBinding(ks,e,condition,pressed);
    I think I know why the requestFocus() is not working. OK, I have a MultipleEditorsPerColumnJTable (sub of JTale), JTextPane, JButton and JLabel. The textpane, label and button have individual editors and renderers. Each time I want to display a new Row, I re-render these components and add it to the table.
    Now with the above code, it still navigates to the next component in the row/ first column in next row depending on the current column. What am I doing wrong?
    Thanks,
    Praveen.

Maybe you are looking for