Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8139113

Impossible to shrink table header size with CSS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u60
    • javafx
    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux jan-x1 3.19.0-30-generic #33~14.04.1-Ubuntu SMP Tue Sep 22 09:27:00 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      (K)ubuntu 14.04
      However this does not seem to be platform-specific problem

      A DESCRIPTION OF THE PROBLEM :
      It is impossible to resize the header row of a TableView using the "-fx-size" CSS property.

      See code sample bellow. Setting the "-fx-size" to 25 should shring the table header to 25 but it does nothing. Increasing the size (e.g. from 25 to 50) works.

      The problem seems to be in TableHeaderRow.java:333 - computePrefHeight(double width) which is called during the change (e.g. from 50->25). The call cornerRegion.height() returns 50 (the old header size) which means the resulting prefHeight of the header is 50 (instead of the new value 25). The underlying cause seems to be that TableHeaderRow.layoutChildren() which should resize the cornerRegion to new size is called too late.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run the attached code sample
      2) Click on the button bellow the table

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The table header shrinks from 50px to 25px
      ACTUAL -
      No visible change

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package com.example;

      import javafx.application.Application;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TableColumnHeightBug extends Application {

          public static void main(String[] args) {
              launch(args);
          }

          @Override
          public void start(Stage primaryStage) throws Exception {
              TableView<String> tableView = new TableView<>();
              tableView.setTableMenuButtonVisible(true);
              TableColumn<String, Object> tableColumn = new TableColumn<>("sample");
              tableColumn.setStyle("-fx-size: 50;");
              tableColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue()));
              tableView.getColumns().add(tableColumn);
              tableView.getItems().addAll("bar", "foo");
              BorderPane root = new BorderPane(tableView);
              Button button = new Button("change header size");
              button.setOnAction(event -> {
                  tableColumn.setStyle("-fx-size: 25;");
              });
              root.setBottom(button);
              primaryStage.setScene(new Scene(root));
              primaryStage.show();
          }
      }
      ---------- END SOURCE ----------

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: