Results 1 to 2 of 2
  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post JTable Cell Focus Listener

    I need to focus JTable cell such that when enter key is pressed it should focus to the next cell of the same row. If it is the last cell it has to go to the next row.

    Your opinions are highly appreciated
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

  2. #2
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    So far i have added a keyListener to my table and used the keyPressed method to handle the key events. The funny thing is, when i press enter key i get an error
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Column index out of range
    BUT when i use the tab key even when am capturing events for the enter key it works alright:confused:
    I just dont know why am getting an error
    below is my code
    Java Code:
    public void keyTyped(KeyEvent e) {}
    public void keyReleased(KeyEvent e) {}
    public void keyPressed(KeyEvent e) {
            int cols = 2;
            int rows = Xenon.getRowCount();
            int key = e.getKeyCode();
                if (key == KeyEvent.VK_ENTER) {
                    int r =Xenon.getSelectedRow();
                    int c =Xenon.getSelectedColumn();
                  if(c < cols) {
                      setSelectedCol(c + 1);
                       return;
                  }
                    if(c == cols) {
                      if(r<rows) {
                            setSelectedRow(r + 1);
                            setSelectedCol(0);
                          Xenon.scrollRectToVisible(Xenon.getCellRect(r + 1, 0, true));
                    }else {
                    setSelectedRow(rows);
                  setSelectedCol(cols);
                }
            }
          }
        }
       public void setSelectedCol(int col) {
         if(col == -1)
            return;
                else {
            Xenon.setColumnSelectionInterval(col, col);
           }
          }
     public void setSelectedRow(int row) {
       if(row == -1)
          return;
         else {
       Xenon.setRowSelectionInterval(row, row);
          }
        }
    Your ideas are highly appreciated
    Thank you
    Last edited by Manfizy; 07-21-2009 at 03:07 PM.
    We Learn Through Mistakes..,
    Manfizy:rolleyes:

Similar Threads

  1. JComboBox in JTable and Cant get Focus...
    By markw8500 in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 12:35 AM
  2. add an undo listener to a Jtable
    By christina in forum Advanced Java
    Replies: 12
    Last Post: 01-29-2009, 08:47 AM
  3. Replies: 0
    Last Post: 11-14-2008, 05:14 AM
  4. jTable Cell editing
    By mahaling_m in forum AWT / Swing
    Replies: 0
    Last Post: 06-23-2008, 09:17 AM
  5. JTable Focus Traversal
    By helios_lie in forum AWT / Swing
    Replies: 1
    Last Post: 12-20-2007, 11:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •