AbstractAction (boolean goDown, boolean withSelection) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int row = goDown ? getNextRow() : getPrevRow(); if (row != -1) { selectRow(row, withSelection); } } }; }