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

JavaFx TableView ignoring the CSS font size in its width computation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx11, jfx12, jfx13, 8u202, 9
    • javafx
    • x86_64
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 / JDK 13.0.1 / OpenJfx 13.0.1

      A DESCRIPTION OF THE PROBLEM :
      When setting a bigger font size to a TableView the header seems to compute the width without applying the CSS. The TableCells however compute this correctly.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run my example code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The first column in my code example has a long header. I expected the TableHeader to apply the font size and after that compute its width. However the header had exact the same width than the one with the standard font size. The second column in my example has a long cell text. There the font size is considered when the column width is being computed.

      ---------- BEGIN SOURCE ----------
      import java.util.Arrays;

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.geometry.HPos;
      import javafx.scene.Scene;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.Priority;
      import javafx.stage.Stage;

      public class TableFontsizeBug extends Application {

        @Override
        public void start(Stage primaryStage) {
          TableView<String> tableStandardSize = new TableView<>();

          TableColumn<String, String> col1 = new TableColumn<>();
          col1.setText("This is a long caption to test its resizing");
          col1.setCellValueFactory(p -> new SimpleStringProperty("Test"));

          TableColumn<String, String> col2 = new TableColumn<>("Test");
          col2.setCellValueFactory(p -> new SimpleStringProperty(
              "This is a longer text to see what happens. This is a longer text to see what happens."));

          final ObservableList<String> row = FXCollections.observableArrayList("");
          tableStandardSize.setItems(row);
          tableStandardSize.getColumns().addAll(Arrays.asList(col1, col2));

          TableView<String> tableIncreasedSize = new TableView<>();
          tableIncreasedSize.setStyle("-fx-font-size: 25");

          TableColumn<String, String> colIncreased1 = new TableColumn<>();
          colIncreased1.setText("This is a long caption to test its resizing");
          colIncreased1.setCellValueFactory(p -> new SimpleStringProperty("Test"));

          TableColumn<String, String> colIncreased2 = new TableColumn<>("Test");
          colIncreased2.setCellValueFactory(p -> new SimpleStringProperty(
              "This is a longer text to see what happens. This is a longer text to see what happens."));

          final ObservableList<String> rowIncreased = FXCollections.observableArrayList("");
          tableIncreasedSize.setItems(rowIncreased);
          tableIncreasedSize.getColumns().addAll(Arrays.asList(colIncreased1, colIncreased2));

          GridPane gridPane = new GridPane();
          final ColumnConstraints col = new ColumnConstraints();
          col.setFillWidth(true);
          col.setHgrow(Priority.ALWAYS);
          col.setHalignment(HPos.CENTER);
          gridPane.getColumnConstraints().add(col);

          gridPane.add(tableStandardSize, 0, 0);
          gridPane.add(tableIncreasedSize, 0, 1);

          Scene scene = new Scene(gridPane, 1400, 400);

          primaryStage.setScene(scene);
          primaryStage.show();

        }

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

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            aghaisas Ajit Ghaisas
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: