diff --git a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TreeViewSkin.java b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TreeViewSkin.java --- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TreeViewSkin.java +++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TreeViewSkin.java @@ -383,8 +383,7 @@ } /** - * Function used to scroll the container down by one 'page', although - * if this is a horizontal container, then the scrolling will be to the right. + * Function used to scroll the container down by one 'page'. */ public int onScrollPageDown(int anchor) { TreeCell lastVisibleCell = flow.getLastVisibleCellWithinViewPort(); @@ -415,8 +414,7 @@ } /** - * Function used to scroll the container up by one 'page', although - * if this is a horizontal container, then the scrolling will be to the left. + * Function used to scroll the container up by one 'page'. */ public int onScrollPageUp(int anchor) { TreeCell firstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); diff --git a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java --- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java +++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java @@ -1890,15 +1890,19 @@ return cell.isEmpty() ? null : cell; } + // Returns last visible cell whose bounds are entirely within the viewport public T getLastVisibleCellWithinViewPort() { if (cells.isEmpty() || getViewportLength() <= 0) return null; T cell; + final double max = isVertical() ? getHeight() : getWidth(); for (int i = cells.size() - 1; i >= 0; i--) { cell = cells.get(i); if (cell.isEmpty()) continue; - if (cell.getLayoutY() < getHeight()) { + final double cellStart = getCellPosition(cell); + final double cellEnd = cellStart + getCellLength(cell); + if (cellEnd <= max) { return cell; } } @@ -1906,18 +1910,17 @@ return null; } + // Returns first visible cell whose bounds are entirely within the viewport public T getFirstVisibleCellWithinViewPort() { if (cells.isEmpty() || getViewportLength() <= 0) return null; - final boolean isVertical = isVertical(); T cell; for (int i = 0; i < cells.size(); i++) { cell = cells.get(i); if (cell.isEmpty()) continue; - if (isVertical && cell.getLayoutY() + cell.getHeight() > 0) { - return cell; - } else if (! isVertical && cell.getLayoutX() + cell.getWidth() > 0) { + final double cellStart = getCellPosition(cell); + if (cellStart >= 0) { return cell; } }