public void actionPerformed(ActionEvent e) { JGrid grid = (JGrid) e.getSource(); if (toLimit) { if (vertically) { int rowCount = grid.getRowCount(); this.dx = 0; this.dy = forwards ? rowCount : -rowCount; } else { int colCount = grid.getColumnCount(); this.dx = forwards ? colCount : -colCount; this.dy = 0; } } else { if (!(grid.getParent().getParent() instanceof JScrollPane)) { return; } Dimension delta = grid.getParent().getSize(); SelectionModel sm = grid.getSelectionModel(); int start = 0; if (vertically) { start = (extend) ? sm.getLeadRow() : sm.getAnchorRow(); } else { start = (extend) ? sm.getLeadColumn() : sm.getAnchorColumn(); } if (vertically) { Rectangle r = grid.getCellBounds(start, 0); r.y += forwards ? delta.height : -delta.height; this.dx = 0; int newRow = grid.rowAtPoint(r.getLocation()); if (newRow == -1 && forwards) { newRow = grid.getRowCount(); } this.dy = newRow - start; } else { Rectangle r = grid.getCellBounds(0, start); r.x += forwards ? delta.width : -delta.width; int newColumn = grid.columnAtPoint(r.getLocation()); if (newColumn == -1 && forwards) { newColumn = grid.getColumnCount(); } this.dx = newColumn - start; this.dy = 0; } } super.actionPerformed(e); }