changeset 11259:b55ec331cd0f

8222214: TableView rows disappears when inside a pane and KEY_UP is pressed Reviewed-by: kcr, aghaisas Contributed-by: thiago.sayao@clamed.com.br
author aghaisas
date Wed, 08 May 2019 14:13:30 +0530
parents 6e7ea94e3638
children 3e09b6bdf762
files modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TableViewBehaviorBase.java modules/javafx.controls/src/test/java/test/javafx/scene/control/TableViewKeyInputTest.java
diffstat 2 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TableViewBehaviorBase.java	Sat May 04 17:59:57 2019 +0200
+++ b/modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/TableViewBehaviorBase.java	Wed May 08 14:13:30 2019 +0530
@@ -860,8 +860,7 @@
         int currentRow = focusedCell.getRow();
         int currentColumn = getVisibleLeafIndex(focusedCell.getTableColumn());
 
-        if (rowDiff < 0 && currentRow <= 0) return;
-        else if (rowDiff > 0 && currentRow >= getItemCount() - 1) return;
+        if (rowDiff > 0 && currentRow >= getItemCount() - 1) return;
         else if (columnDiff < 0 && currentColumn <= 0) return;
         else if (columnDiff > 0 && currentColumn >= getVisibleLeafColumns().size() - 1) return;
         else if (columnDiff > 0 && currentColumn == -1) return;
@@ -869,7 +868,10 @@
         TableColumnBase tc = focusedCell.getTableColumn();
         tc = getColumn(tc, columnDiff);
 
-        int row = focusedCell.getRow() + rowDiff;
+        //JDK-8222214: Moved this "if" here because the first row might be focused and not selected, so
+        // this makes sure it gets selected when the users presses UP. If not it ends calling
+        // VirtualFlow.scrollTo(-1) at and the content of the TableView disappears.
+        int row = (currentRow <= 0 && rowDiff <= 0) ? 0 : focusedCell.getRow() + rowDiff;
         sm.clearAndSelect(row, tc);
         setAnchor(row, tc);
     }
--- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/TableViewKeyInputTest.java	Sat May 04 17:59:57 2019 +0200
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/TableViewKeyInputTest.java	Wed May 08 14:13:30 2019 +0530
@@ -4307,4 +4307,11 @@
         assertEquals(1, sm.getSelectedIndex());
         assertEquals(1, fm.getFocusedIndex());
     }
+
+    @Test public void test_jdk_8222214() {
+        tableView.getFocusModel().focus(0);
+        keyboard.doUpArrowPress();
+
+        assertEquals(0, tableView.getSelectionModel().getSelectedIndex());
+    }
 }