diff --git a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableViewSkinBase.java b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableViewSkinBase.java --- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableViewSkinBase.java +++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableViewSkinBase.java @@ -433,6 +433,9 @@ * if this is a horizontal container, then the scrolling will be to the right. */ public int onScrollPageDown(boolean isFocusDriven) { + TableSelectionModel sm = getSelectionModel(); + if (sm == null) return -1; + final int itemCount = getItemCount(); I lastVisibleCell = flow.getLastVisibleCellWithinViewPort(); @@ -454,12 +457,17 @@ } if (isSelected) { - // if the last visible cell is selected, we want to shift that cell up - // to be the top-most cell, or at least as far to the top as we can go. - flow.showAsFirst(lastVisibleCell); + boolean scrollFlow = (isFocusDriven && getFocusModel().getFocusedIndex() == lastVisibleCellIndex) + || (! isFocusDriven && sm.getSelectedIndex() == lastVisibleCellIndex); - I newLastVisibleCell = flow.getLastVisibleCellWithinViewPort(); - lastVisibleCell = newLastVisibleCell == null ? lastVisibleCell : newLastVisibleCell; + if (scrollFlow) { + // if the last visible cell is selected, we want to shift that cell up + // to be the top-most cell, or at least as far to the top as we can go. + flow.showAsFirst(lastVisibleCell); + + I newLastVisibleCell = flow.getLastVisibleCellWithinViewPort(); + lastVisibleCell = newLastVisibleCell == null ? lastVisibleCell : newLastVisibleCell; + } } int newSelectionIndex = lastVisibleCell.getIndex(); @@ -473,9 +481,11 @@ * if this is a horizontal container, then the scrolling will be to the left. */ public int onScrollPageUp(boolean isFocusDriven) { + TableSelectionModel sm = getSelectionModel(); + I firstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); if (firstVisibleCell == null) return -1; - + int firstVisibleCellIndex = firstVisibleCell.getIndex(); // isSelected represents focus OR selection @@ -487,12 +497,17 @@ } if (isSelected) { - // if the first visible cell is selected, we want to shift that cell down - // to be the bottom-most cell, or at least as far to the bottom as we can go. - flow.showAsLast(firstVisibleCell); + boolean scrollFlow = (isFocusDriven && getFocusModel().getFocusedIndex() == firstVisibleCellIndex) + || (! isFocusDriven && sm.getSelectedIndex() == firstVisibleCellIndex); - I newFirstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); - firstVisibleCell = newFirstVisibleCell == null ? firstVisibleCell : newFirstVisibleCell; + if (scrollFlow) { + // if the first visible cell is selected, we want to shift that cell down + // to be the bottom-most cell, or at least as far to the bottom as we can go. + flow.showAsLast(firstVisibleCell); + + I newFirstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); + firstVisibleCell = newFirstVisibleCell == null ? firstVisibleCell : newFirstVisibleCell; + } } int newSelectionIndex = firstVisibleCell.getIndex();