diff --git a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java --- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java +++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ListViewSkin.java @@ -406,23 +406,22 @@ final FocusModel fm = getSkinnable().getFocusModel(); if (sm == null || fm == null) return -1; - int newSelectionIndex = -1; int lastVisibleCellIndex = lastVisibleCell.getIndex(); if (sm.isSelected(lastVisibleCellIndex) || fm.isFocused(lastVisibleCellIndex) || lastVisibleCellIndex == anchor) { // 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); - lastVisibleCell = flow.getLastVisibleCellWithinViewPort(); - newSelectionIndex = lastVisibleCell.getIndex(); + ListCell newLastVisibleCell = flow.getLastVisibleCellWithinViewPort(); + lastVisibleCell = newLastVisibleCell == null ? lastVisibleCell : newLastVisibleCell; } else { // if the selection is not on the 'bottom' most cell, we firstly move - // the selection down to that, without scrolling the contents - newSelectionIndex = lastVisibleCell.getIndex(); - } + // the selection down to that, without scrolling the contents, so + // this is a no-op + } + int newSelectionIndex = lastVisibleCell.getIndex(); flow.show(lastVisibleCell); - return newSelectionIndex; } @@ -438,23 +437,22 @@ final FocusModel fm = getSkinnable().getFocusModel(); if (sm == null || fm == null) return -1; - int newSelectionIndex = -1; int firstVisibleCellIndex = firstVisibleCell.getIndex(); if (sm.isSelected(firstVisibleCellIndex) || fm.isFocused(firstVisibleCellIndex) || firstVisibleCellIndex == anchor) { // 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); - firstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); - newSelectionIndex = firstVisibleCell.getIndex(); + ListCell newFirstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); + firstVisibleCell = newFirstVisibleCell == null ? firstVisibleCell : newFirstVisibleCell; } else { // if the selection is not on the 'top' most cell, we firstly move - // the selection up to that, without scrolling the contents - newSelectionIndex = firstVisibleCell.getIndex(); + // the selection up to that, without scrolling the contents, so + // this is a no-op } + int newSelectionIndex = firstVisibleCell.getIndex(); flow.show(firstVisibleCell); - return newSelectionIndex; } } 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 @@ -454,7 +454,9 @@ // 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); - lastVisibleCell = flow.getLastVisibleCellWithinViewPort(); + + I newLastVisibleCell = flow.getLastVisibleCellWithinViewPort(); + lastVisibleCell = newLastVisibleCell == null ? lastVisibleCell : newLastVisibleCell; } int newSelectionIndex = lastVisibleCell.getIndex(); @@ -482,8 +484,10 @@ // 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); - firstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); - } + + I newFirstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); + firstVisibleCell = newFirstVisibleCell == null ? firstVisibleCell : newFirstVisibleCell; + } int newSelectionIndex = firstVisibleCell.getIndex(); flow.show(newSelectionIndex); 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 @@ -393,23 +393,22 @@ final FocusModel fm = getSkinnable().getFocusModel(); if (sm == null || fm == null) return -1; - int newSelectionIndex = -1; int lastVisibleCellIndex = lastVisibleCell.getIndex(); if (sm.isSelected(lastVisibleCellIndex) || fm.isFocused(lastVisibleCellIndex) || lastVisibleCellIndex == anchor) { // 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); - lastVisibleCell = flow.getLastVisibleCellWithinViewPort(); - newSelectionIndex = lastVisibleCell.getIndex(); + TreeCell newLastVisibleCell = flow.getLastVisibleCellWithinViewPort(); + lastVisibleCell = newLastVisibleCell == null ? lastVisibleCell : newLastVisibleCell; } else { // if the selection is not on the 'bottom' most cell, we firstly move - // the selection down to that, without scrolling the contents - newSelectionIndex = lastVisibleCell.getIndex(); + // the selection down to that, without scrolling the contents, so + // this is a no-op } + int newSelectionIndex = lastVisibleCell.getIndex(); flow.show(lastVisibleCell); - return newSelectionIndex; } @@ -424,23 +423,22 @@ final FocusModel fm = getSkinnable().getFocusModel(); if (sm == null || fm == null) return -1; - int newSelectionIndex = -1; int firstVisibleCellIndex = firstVisibleCell.getIndex(); if (sm.isSelected(firstVisibleCellIndex) || fm.isFocused(firstVisibleCellIndex) || firstVisibleCellIndex == anchor) { // 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); - firstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); - newSelectionIndex = firstVisibleCell.getIndex(); + TreeCell newFirstVisibleCell = flow.getFirstVisibleCellWithinViewPort(); + firstVisibleCell = newFirstVisibleCell == null ? firstVisibleCell : newFirstVisibleCell; } else { // if the selection is not on the 'top' most cell, we firstly move - // the selection up to that, without scrolling the contents - newSelectionIndex = firstVisibleCell.getIndex(); - } + // the selection up to that, without scrolling the contents, so + // this is a no-op + } + int newSelectionIndex = firstVisibleCell.getIndex(); flow.show(firstVisibleCell); - return newSelectionIndex; } }