== KeyEvent.VK_SLASH) && evt.isControlDown()) { rowModel.setSelectionInterval(0, rowMax); colModel.setSelectionInterval(0, colMax);    rowModel.addSelectionInterval(rowLead, rowLead); colModel.addSelectionInterval(colLead, colLead);
== KeyEvent.VK_SLASH) && (evt.getModifiers() == InputEvent.CTRL_MASK)) { table.selectAll();
    public void keyPressed(KeyEvent evt)     {      ListSelectionModel rowModel = table.getSelectionModel();      ListSelectionModel colModel = table.getColumnModel().getSelectionModel();      int rowLead = rowModel.getLeadSelectionIndex();      int rowMax = table.getModel().getRowCount() - 1;      int colLead = colModel.getLeadSelectionIndex();      int colMax = table.getModel().getColumnCount() - 1;      if ((evt.getKeyCode() == KeyEvent.VK_DOWN)          || (evt.getKeyCode() == KeyEvent.VK_KP_DOWN))        {          if (!evt.isShiftDown())            {                            table.clearSelection();              rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax),                                            Math.min(rowLead + 1, rowMax));              colModel.setSelectionInterval(colLead,colLead);            }          else             {              rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax));              colModel.setLeadSelectionIndex(colLead);            }        }      else if ((evt.getKeyCode() == KeyEvent.VK_UP)               || (evt.getKeyCode() == KeyEvent.VK_KP_UP))        {          if (!evt.isShiftDown())            {              table.clearSelection();              rowModel.setSelectionInterval(Math.max(rowLead - 1, 0),                                            Math.max(rowLead - 1, 0));              colModel.setSelectionInterval(colLead,colLead);            }          else            {              rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0));              colModel.setLeadSelectionIndex(colLead);            }        }      else if ((evt.getKeyCode() == KeyEvent.VK_LEFT)               || (evt.getKeyCode() == KeyEvent.VK_KP_LEFT))        {          if (evt.isShiftDown())            {              colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0));              rowModel.setLeadSelectionIndex(rowLead);            }          else            {              table.clearSelection();              rowModel.setSelectionInterval(rowLead,rowLead);              colModel.setSelectionInterval(Math.max(colLead - 1, 0),                                            Math.max(colLead - 1, 0));            }        }      else if ((evt.getKeyCode() == KeyEvent.VK_RIGHT)               || (evt.getKeyCode() == KeyEvent.VK_KP_RIGHT))        {          if (evt.isShiftDown())            {              colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax));              rowModel.setLeadSelectionIndex(rowLead);            }          else            {              table.clearSelection();              rowModel.setSelectionInterval(rowLead,rowLead);              colModel.setSelectionInterval(Math.min(colLead + 1, colMax),                                            Math.min(colLead + 1, colMax));            }        }      else if (evt.getKeyCode() == KeyEvent.VK_END)        {          if (evt.isControlDown() && evt.isShiftDown())            {              rowModel.setLeadSelectionIndex(rowMax);              colModel.setLeadSelectionIndex(colLead);            }          else if (evt.isControlDown())            {              table.clearSelection();              rowModel.setSelectionInterval(rowMax,rowMax);              colModel.setSelectionInterval(colLead, colLead);            }          else if (evt.isShiftDown())            {              colModel.setLeadSelectionIndex(colMax);              rowModel.setLeadSelectionIndex(rowLead);            }          else            {              table.clearSelection();              rowModel.setSelectionInterval(rowLead, rowLead);              colModel.setSelectionInterval(colMax, colMax);            }         }      else if (evt.getKeyCode() == KeyEvent.VK_HOME)        {          if (evt.isControlDown() && evt.isShiftDown())            {              rowModel.setLeadSelectionIndex(0);              colModel.setLeadSelectionIndex(colLead);            }          else if (evt.isControlDown())            {              table.clearSelection();              rowModel.setSelectionInterval(0,0);              colModel.setSelectionInterval(colLead, colLead);    }          else if (evt.isShiftDown())            {              colModel.setLeadSelectionIndex(0);              rowModel.setLeadSelectionIndex(rowLead);            }          else            {              table.clearSelection();              rowModel.setSelectionInterval(rowLead, rowLead);              colModel.setSelectionInterval(0, 0);            }        }      else if (evt.getKeyCode() == KeyEvent.VK_F2)        {          // FIXME: Implement "start editing"        }      else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP)        {          // FIXME: implement, need JList.ensureIndexIsVisible to work        }      else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN)        {          // FIXME: implement, need JList.ensureIndexIsVisible to work        }      else if (evt.getKeyCode() == KeyEvent.VK_TAB)        {          // FIXME: Implement select next column          // NOTE: TAB doesn't get recognized by this KeyHandler          // something must be intercepting it and using it to change          // focus        }      else if (evt.getKeyCode() == KeyEvent.VK_ENTER)        {          // If nothing is selected, select the first cell in the table          if (table.getSelectedRowCount() == 0 &&               table.getSelectedColumnCount() == 0)            {              rowModel.setSelectionInterval(0, 0);              colModel.setSelectionInterval(0, 0);              return;            }                    // If the lead selection index isn't selected (ie a remove operation          // happened, then set the lead to the first selected cell in the          // table          if (!table.isCellSelected(rowLead, colLead))            {              rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(),                                             rowModel.getMinSelectionIndex());              colModel.addSelectionInterval(colModel.getMinSelectionIndex(),                                             colModel.getMinSelectionIndex());              return;            }          // If there is just one cell selected, select the next row, and wrap          // when you get to the edges of the table.          if ((table.getSelectedRowCount() <= 1 &&                table.getSelectedColumnCount() <= 1)              || (table.getRowSelectionAllowed() == false &&                   table.getColumnSelectionAllowed() == false))            {              rowModel.setSelectionInterval((rowLead + 1)%(rowMax + 1),                                             (rowLead + 1)%(rowMax + 1));              if (rowLead == rowMax)                colModel.setSelectionInterval((colLead + 1)%(colMax + 1),                                               (colLead + 1)%(colMax + 1));              else                colModel.setSelectionInterval(colLead, colLead);              return;            }          // Otherwise select the next row and wrap when you get to the edges          // of the selection.  So you only move the lead indices around          // amongst the already selected cells.          // If the row lead index is at the end of the selection, wrap it around          int rowMaxSelected = table.getRowSelectionAllowed() ?             rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1;          int rowMinSelected = table.getRowSelectionAllowed() ?             rowModel.getMinSelectionIndex() : 0;           int colMaxSelected = table.getColumnSelectionAllowed() ?             colModel.getMaxSelectionIndex() :             table.getModel().getColumnCount() - 1;          int colMinSelected = table.getColumnSelectionAllowed() ?             colModel.getMinSelectionIndex() : 0;          if (rowLead == rowMaxSelected)            {              rowModel.addSelectionInterval(rowMinSelected, rowMinSelected);                            // And select the next column (from within the selection)              if (colLead == colMaxSelected)                colModel.addSelectionInterval(colMinSelected, colMinSelected);              else                {                  int[] colsSelected;                  if (table.getColumnSelectionAllowed())                    colsSelected = table.getSelectedColumns();                  else                    {                      colsSelected = new int[table.getModel().getColumnCount()];                      for (int i = 0; i < table.getModel().getColumnCount(); i++)                        colsSelected[i] = i;                    }                  int colIndex = 0;                  while (colsSelected[colIndex] <= colLead)                    colIndex++;                  colModel.addSelectionInterval(colsSelected[colIndex],                                                 colsSelected[colIndex]);                }            }          // If the row lead index isn't at the end, just advance it          // and you don't have to update the column index          else            {              int[] rowsSelected;              if (table.getRowSelectionAllowed())                rowsSelected = table.getSelectedRows();              else                {                  rowsSelected = new int[table.getModel().getRowCount()];                  for (int i = 0; i < table.getModel().getRowCount(); i++)                    rowsSelected[i] = i;                }              int rowIndex = 0;              while (rowsSelected[rowIndex] <= rowLead)                rowIndex++;              rowModel.addSelectionInterval(rowsSelected[rowIndex],                                             rowsSelected[rowIndex]);              colModel.addSelectionInterval(colLead, colLead);            }          table.repaint();        }      else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE)        {          // FIXME: implement "cancel"        }      else if ((evt.getKeyCode() == KeyEvent.VK_A || evt.getKeyCode()                == KeyEvent.VK_SLASH) && evt.isControlDown())        {          rowModel.setSelectionInterval(0, rowMax);          colModel.setSelectionInterval(0, colMax);          // the next two lines are to restore the lead selection indices to           // their previous values, because select-all operations shouldn't           // change them          rowModel.addSelectionInterval(rowLead, rowLead);          colModel.addSelectionInterval(colLead, colLead);        }      else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH               && evt.isControlDown())        {          table.clearSelection();        }    }