changeset 10694:3ee52fa5dd55 jdk-10+31

8188164: Visual glitch / layout issue when setting pref height of table column headers Reviewed-by: kcr
author aghaisas
date Tue, 07 Nov 2017 08:54:15 +0530
parents beafd0f2d662
children 20bf31a9c865 394ff0e846b9
files modules/javafx.controls/src/main/java/javafx/scene/control/skin/NestedTableColumnHeader.java modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/TableViewSkinTest.java modules/javafx.controls/src/test/resources/test/javafx/scene/control/skin/TableViewSkinTest.css
diffstat 3 files changed, 79 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/NestedTableColumnHeader.java	Mon Nov 06 13:31:00 2017 -0800
+++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/NestedTableColumnHeader.java	Tue Nov 07 08:54:15 2017 +0530
@@ -279,9 +279,10 @@
         double w = getWidth() - snappedLeftInset() - snappedRightInset();
         double h = getHeight() - snappedTopInset() - snappedBottomInset();
 
-        int labelHeight = (int) label.prefHeight(-1);
+        int labelHeight = 0;
 
-        if (label.isVisible()) {
+        if (label.isVisible() && getTableColumn() != null) {
+            labelHeight = (int) label.prefHeight(-1);
             // label gets to span whole width and sits at top
             label.resize(w, labelHeight);
             label.relocate(snappedLeftInset(), snappedTopInset());
@@ -351,7 +352,12 @@
             }
         }
 
-        return height + label.prefHeight(-1) + snappedTopInset() + snappedBottomInset();
+        double labelHeight = 0.0;
+        if (label.isVisible() && getTableColumn() != null) {
+            labelHeight = label.prefHeight(-1);
+        }
+
+        return height + labelHeight + snappedTopInset() + snappedBottomInset();
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/TableViewSkinTest.java	Tue Nov 07 08:54:15 2017 +0530
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.javafx.scene.control.skin;
+
+import com.sun.javafx.tk.Toolkit;
+import javafx.scene.Group;
+import javafx.scene.Node;
+import javafx.scene.Scene;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.skin.TableHeaderRow;
+import javafx.scene.control.skin.TableViewSkin;
+import javafx.stage.Stage;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class TableViewSkinTest {
+    @Test
+    public void test_JDK_8188164() {
+        TableView<String> tableView = new TableView<>();
+        for (int i = 0; i < 5; i++) {
+            TableColumn<String, String> column = new TableColumn<>("Col " + i);
+            tableView.getColumns().add(column);
+        }
+
+        Scene scene = new Scene(tableView);
+        scene.getStylesheets().add(TableViewSkinTest.class.getResource("TableViewSkinTest.css").toExternalForm());
+
+        Toolkit tk = Toolkit.getToolkit();
+
+        Stage stage = new Stage();
+        stage.setScene(scene);
+        stage.setWidth(500);
+        stage.setHeight(400);
+        stage.centerOnScreen();
+        stage.show();
+
+        tk.firePulse();
+
+        TableHeaderRow header = (TableHeaderRow)tableView.lookup("TableHeaderRow");
+        assertEquals("Table Header height specified in CSS",
+                      100.0, header.getHeight(), 0.001);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.controls/src/test/resources/test/javafx/scene/control/skin/TableViewSkinTest.css	Tue Nov 07 08:54:15 2017 +0530
@@ -0,0 +1,3 @@
+.column-header {
+    -fx-pref-height: 100px;
+}