How can I change the focus on a row in a JTable using a toolbar button? (For example: clicking forward/previous buttons.)

Jesper Berglund

The JTable class has a method which sets the selected row interval. Use that method to set the selected row.


public void forwardButton_ActionPerformed(ActionEvent e) {
  if (aTable.getRowCount() > 0 && 
      aTable.getSelectedRow < aTable.getRowCount() - 1)
       (aTable.getSelectedRow+1, aTable.getSelectedRow+1);

public void previousButton_ActionPerformed(ActionEvent e) {
  if (aTable.getRowCount() > 0 &&
      aTable.getSelectedRow > 0)
        (aTable.getSelectedRow-1, aTable.getSelectedRow-1);
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.