// NOTE we don't invalidate the component here because we need only
// reposition the view and column header. Invalidating would yield
// the correct positioning, but it would do much more work than needed.
ScrollPane scrollPane = (ScrollPane)viewport;
Component view = scrollPane.getView();
Component rowHeader = scrollPane.getRowHeader();
Component columnHeader = scrollPane.getColumnHeader();
int rowHeaderWidth = 0;
if (rowHeader != null) {
rowHeaderWidth = rowHeader.getWidth();
}
int scrollLeft = scrollPane.getScrollLeft();
if (view != null
&& view.isShowing()
&& isOptimizeScrolling()) {
Bounds blitArea = view.getVisibleArea();
int blitX = blitArea.x + view.getX();
int blitY = blitArea.y + view.getY();
int blitWidth = blitArea.width;
int blitHeight = blitArea.height;
if (columnHeader != null) {
// Blit the column header as well
int columnHeaderHeight = columnHeader.getHeight();
blitY -= columnHeaderHeight;
blitHeight += columnHeaderHeight;
}
int deltaScrollLeft = scrollLeft - previousScrollLeft;
blitX += Math.max(deltaScrollLeft, 0);
blitWidth -= Math.abs(deltaScrollLeft);
Graphics2D graphics = scrollPane.getGraphics();
graphics.copyArea(blitX, blitY, blitWidth, blitHeight, -deltaScrollLeft, 0);
scrollPane.setConsumeRepaint(true);
try {
view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
if (columnHeader != null) {
columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
}
} finally {
scrollPane.setConsumeRepaint(false);
}
boolean repaintAllViewport = scrollPane.isRepaintAllViewport();
if (!repaintAllViewport) {
scrollPane.repaint(rowHeaderWidth + (deltaScrollLeft > 0 ? blitWidth : 0), blitY,
Math.abs(deltaScrollLeft), blitHeight, true);
} else {
Bounds viewportBounds = getViewportBounds();
scrollPane.repaint(viewportBounds.x, viewportBounds.y,
viewportBounds.width, viewportBounds.height, true);
}
} else {
if (view != null) {
view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
}
if (columnHeader != null) {
columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
}
}
if (scrollLeft >= 0 && scrollLeft <= getMaxScrollLeft()) {
horizontalScrollBar.setValue(scrollLeft);