Key navigation for JTable

I have a JTable and i need to select its rows during key navigation.
Say i have 23 columns in this table and just for test purposes everytime on keypressed i want to select 2nd row. I am doing it in following way within KeyPressed Event.
int[] indexes = table.getSelectedRows();
table.requestFocus();
int[] cols = table.getSelectedColumns();
for (int xx=0; xx<cols.length; xx++ )
table.removeColumnSelectionInterval(cols[xx],cols[xx]);
table.removeRowSelectionInterval(indexes[0],indexes[0]);
table.setColumnSelectionInterval(0,22);
table.setRowSelectionInterval(2,2);
But this doesn't seem to work on keypressed event although it works fine if i call it from some other place like a button pressed. Any help gurus ???
TIA

Sorry i missed to mention what it actually seems to do. It only selected the 1st column when this piece of code is called from KeyPressed Event.
But when the same code is called from any other place it selects all the 23 columns.
I will appreciate any help on this bottleneck problem for me.

Similar Messages

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

  • How to detect key navigation in JTable

    Hi,
    I have a problem with JTable's events. When the user presses the mouse's left button on a cell, a mouseClicked event is generated, and my program works fine. But when the user moves from cell to cell with the cursor keys or the tab key, no mouseClicked event is generated, and my event code doesn't execute. I have seen listeners like TableColumnModelListener, but I don't want two or more events at the same time: i.e. if I go from cell 1,1 to cell 2,2, I just want one event, not one for the column and another for the row. I just want ONE event for "selection change", originated by mouse or keyboard. What should I use?
    I'm using Java 1.4.
    Thanks.

    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to use Key Bindings

  • Navigation for jtables

    Hello,
    I have a jtable which is displayed in a jpanel. The jtable can fit around 30 rows in. The data I show requires around 100 rows. The system is for a touchscreen so I was going to add an up and down JButton.
    I want to represent this as page X of X. When the down button is pressed the page text changes to Page 2 of 10 and the table view moves down to the next ‘page’
    The height of the rows is not fixed.
    What’s the best way to do this?
    cheers
    Bobby

    Hi,
    You can query up the record in PO Summary form. Then Navigate to Tools->Control Actions.
    And a pop-up window pops up which will display all the valid actions for the document.
    You can cancel the PO on Header, Line or Shipment level. But you can put the PO on Hold at Header Level.
    You can cancel the PO from the Enter PO form as well.
    And if this is R12 you can also do it from Purchasing OA pages.
    Thanks
    Arun
    Message was edited by:
    Arun Das

  • How do I get key navigation to work in Labview PDA?

    I want to be able to press a key on my Windows CE device and toggle a boolean control on my application.  However, when I set the key navigation for the control to toggle with F1, it doesn't work?  What am I doing wrong?

    Key navigation and using tab to switch between front panel controls are not supported. You can find more information regarding this from the LabVIEW 8 Help under PDA Module >> Creating  PDA VIs >> Designing PDA VI Front Panels.
    If you would like to make a product suggestion that this be supported, I would encourage you to go to ni.com and click Contact NI.
    Jarrod S.
    National Instruments

  • Regarding Tab key Navigation in a page

    Hi,
    I have a requirement regarding the tab key navigation on a page.
    Suppose the focus is on the last field of a page, on clicking the tab key i should go to the first field in the page not the url. i tried using tab index, but the problem is that after coming back to the first field from the last field, on clicking on tab again it does not go on as usual, it suddenly jumps to the url from there.
    Regards
    Krishna

    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.

  • Key navigation

    how can i use Key navigation ( Enter KeY)For two boolean ( Ok1,OK2)in one vi,because it work only for one when irun the program.
    someone can help me with a sample
    Attachments:
    Key.vi ‏54 KB

    Instead of using Key Navigation, try the event structure like in the attached example. I didn't use the Booleans in the example but you can add those as well.
    Attachments:
    Key_mod.vi ‏56 KB

  • Focus management for JTable (J2SE 1.4)

    hi,
    I am using J2SE 1.4 currently. Java 1.4 defines JTables as FocusCycleRoots. That is, when they are tabbed into, focus becomes "trapped" within them, so the Tab key in a JTable causes the focus to traverse to the next cell. But I want give the focus to the next component (e.g JButton, JTextField, etc.), not one of its cells.
    Anybody knows how solve this problem? Thanks a lot.

    isManagingFocus is deprecated in 1.4 so it's probably best not to use that.
    Also, JTable isn't actually a focus cycle root. It's simply operating on the key bindings that it has by default. That is, TAB moves the selection from cell to cell and Ctrl-TAB moves to the next focusable component (after the JTable).
    I think the recommended way to approach it is to set the focus traversal keys something like this
    // get your table from somewhere
    JTable table = new JTable();
    // use java.awt.AWTKeyStroke to set up the appropriate focus
    // traversal keys
    AWTKeyStroke tab = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0);
    AWTKeyStroke shiftTab = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK);
    AWTKeyStroke ctrlTab = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK);
    AWTKeyStroke ctrlShiftTab = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    // create a java.util.Set for forwards and backwards focus traversal
    // keys. The actual concrete Set you use probably doesn't matter.
    // I've used a java.util.HashSet
    HashSet forwardKeys = new HashSet();
    HashSet backwardKeys = new HashSet();
    // add the appropriate keys to the appropriate sets
    forwardKeys.add(tab);
    forwardKeys.add(ctrlTab);
    backwardKeys.add(shiftTab);
    backwardKeys.add(ctrlShiftTab);
    // set the focus traversal keys on the table.
    table.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
    table.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardKeys);

  • Use spacebar to toggle in key navigation

    I want to use the spacebar as a start stop button in my application. It's not listed under key navigation is there a way to do it programmatically?
    Solved!
    Go to Solution.

    The terminals inside the event case have Char and Scan Code, you can read either one and compare it to the value for space (Char =32,  Scan Code = 57)

  • Can anybody turn off "F2" key bind in JTable

    Hi all,
    I have following problem,
    I use global key action for key "F2", I also use as JTable cell editor my own editable combobox (extended from JComboBox). I have to turn off "F2" key action, which starts and stops editing cells in JTable, but I dont know how,
    can anybody help me?
    Mathew, HSIGP

    i have found solution: :)
              //deleting of f2
              KeyStroke f2=KeyStroke.getKeyStroke("F2");
              int type=WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
              InputMap imap=getInputMap(type);
              InputMap m=new InputMap();                    
              for (int i=0;i<imap.allKeys().length;i++)
              if (imap.allKeys()!=f2) m.put(imap.allKeys()[i],imap.get(imap.allKeys()[i]));          
              setInputMap(type,m);
              //end of deleting f2
    not best but working :),
    Mathew

  • Key Navigation when window doesn't have focus

    Using key navigation I want to allow the user to instigate a program function by with a key sequence like Ctrl-F1. This works fine as long as the window has focus but does not work if another window is active. Is there any way to get my vi to respond to the key sequence when that vi does not have the focus?

    You can use the keyboard input VIs to continuously poll for that key combination. Not as good as an event, but will work without focus. The VIs can be found in the Advanced palette before 8.0 and in the Connectivity palette (I think) later.
    Try to take over the world!

  • Key navigation, defining own keys

    Hi,
    i want to control some buttons on the front panel with the keyboard.
    How can i use the cursors (up,down,left,right) for button control. In
    the menu key navigation are only the F1, F2... and some other keys.
    The question is how to customize the key navigation.
    I really hope you can help me.
    Jürgen

    You can't change the keys available to you for keyboard navigation. At least as far as I know. You can, however, make up your own using the keyboard functions that come with LabVIEW. There's an example that ships with LabVIEW that shows you how to do this. You will likely need to use an event structure-based architecture, or something similar.

  • InputMap/ActionMap key bindings for arrow keys, alt key

    I'm having trouble defining InputMap/ActionMap key bindings for the arrow keys and the Alt key. My bound actions never run. I believe the problem is that the arrows are used in focus navigation, and the Alt key is used for opening the menu. How can I get these key bindings to work? Is there any other way that I can get events from these keys? I'd even be happy with simple AWT KeyListener events at this point. Thanks.

    I've been having this same problem. I built a demo application that demonstrates the problem. It all works fine until I add the JTree. The JTree seems to be consuming the arrow key strokes. Here is the code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.KeyStroke;
    public class ArrowKeyDemo extends JFrame implements ActionListener {
        private javax.swing.JTree tree;
        private javax.swing.JPanel panel;
        public ArrowKeyDemo() {
            initComponents();
            panel.registerKeyboardAction(this, "A",
                    KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, false),
                    JComponent.WHEN_IN_FOCUSED_WINDOW);
            panel.registerKeyboardAction(this, "left",
                    KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false),
                    JComponent.WHEN_IN_FOCUSED_WINDOW);
        private void initComponents() {
            panel = new javax.swing.JPanel();
            tree = new javax.swing.JTree();
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            panel.add(tree);
            getContentPane().add(panel, java.awt.BorderLayout.CENTER);
            pack();
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            new ArrowKeyDemo().show();
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent);
    }Having the JTree in there kills the ability to trap key strokes for any other purpose. This seems to be true of other Swing components as well. You can stop the JTree from consuming key strokes by adding the line:
    tree.setActionMap(null);
    But you will probably need to set the ActionMap to null for every Swing component that is trapping key strokes. I'm not 100% sure, but I think that includes scroll panes as well.
    I'd love to hear a more elegant solution.
    --Timothy Rogers

  • Show different key fields for different caracteristics in the column.

    Hi, experts
    I am creating a query where there are 4 colomns reprensenting 4 different dates. But I would like to display diffferent key fields for them. For example, under DAY 1, i would like to diplay KeyField 1, for DAY2, DAY3 and DAY4, KeyField 2 et 3 will be added under them.
    To do that, i made these key fields "Constant selection" and made some definition in the cells-------
    On the line of DAY1 in the colomn KeyField 2 and KeyField 3, I made them "Always Hide".
    But I didn't get what i wanted as the two columns (KF2 et KF3) still appear in the report, even if there are no data in these two columns.
    Is it possible to realise this requirement:
    DAY1   DAY2          DAY3
    KF1     KF2    KF3   KF2     KF3
    Thanks in advance!!!!

    There is no need to define a cell for this, use a restricted key figure:
    KF1 needs to be restricted by Day1
    KF2 restrict it by Day2 and so on,
    and use those restricted figure in the key figure section, but to make the column more descriptive use a text variable for the name of the columns.
    this should be easier than cell definition.
    thanks.
    Wond

  • Key password for the demonstration identity key

    Anybody know the key password for the cert in the DemoIdentity keystore.
              I know the store passphrase but I can't find the key password documented
              anywhere on BEA's web site. Anybody know the private key password?
              Grant

    Disregard this post unless you happend to know the answer. I accidentally
              posted it here when I meant to post it in the security newsgroup.
              Grant
              > Anybody know the key password for the cert in the DemoIdentity
              > keystore. I know the store passphrase but I can't find the key
              > password documented anywhere on BEA's web site. Anybody know the
              > private key password?
              >
              > Grant
              >

Maybe you are looking for

  • Firefox 3.6.10 crashes each time I try to open a PDF file? Any suggestions?

    Each time I try to open a PDF file from any website, Firefox (3.6.10) crashes. No error messages--just closes abruptly. For add-ons, I've got Personas 1.6.1, United States English Dictionary 1.0.0, and WOT. I've got the Adobe Reader 9 and Foxit 3.3.1

  • Bpm 11g error while deploying composite. BPM_CUBE_PROCESS_INDX1

    Hello, Got the following error while deploying the very first composite to a newly installed bpm 11.1.1.5.0 server on windows 2003 server with Oracle 10g Express Data base: Deploying on partition "default" from "/Farm_BPM_11g_Domain/BPM_11g_Domain/so

  • Removing Headers - No Template

    Hello, I inherited a RoboHelp project, orginally developed in X5. The author hard-coded the header information (Name of Book > Topic Title) with no template. I would like to remove the header information and use the Breadcrumbs feature. The project h

  • Cross References Will Not Display Page Number

    Got some documents created in InDesign CS3 (MAC). When bringing them into CS4 (Windows) and trying to create a paragraph cross-reference the page numbers will not display. All the other text in the cross reference ("paragraph", the word "page", etc.)

  • How to put multiple targets in ODI

    Hi All, Can i know how to put multiple targets in Oracle Data Inegrator. Thanks in Advance!!