How can I change the focus on a row in a JTable using a toolbar button? (For example: clicking forward/previous buttons.)
Created May 4, 2012
Jesper Berglund The JTable class has a method which sets the selected row interval. Use that method to set the selected row.
Example:
public void forwardButton_ActionPerformed(ActionEvent e) { if (aTable.getRowCount() > 0 && aTable.getSelectedRow < aTable.getRowCount() - 1) aTable.setRowSelectionInterval (aTable.getSelectedRow+1, aTable.getSelectedRow+1); } public void previousButton_ActionPerformed(ActionEvent e) { if (aTable.getRowCount() > 0 && aTable.getSelectedRow > 0) aTable.setRowSelectionInterval (aTable.getSelectedRow-1, aTable.getSelectedRow-1); }