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

TreeView fixed cell size layouting has issues on HiDPI display

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx11, jfx13
    • javafx
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.17134.765]
      openjdk version "11.0.3" 2019-04-16
      OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      TreeView fixed cell size layouting has issues on HiDPI display.
      It is visible when TreeView's background is other than cell's background.

      The same issue probably applies for TableView.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Startup the provided application on display with 125% dpi.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      TreeView cells should not have red vertical lines between them
      ACTUAL -
      TreeView cells have gaps between each other, so background color of table is visible between them.

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

      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TreeViewCellGapsIssue
      {

          public static void main( String[] args )
          {
              System.err.println( Runtime.version().toString() );
              Application.launch( MainFx.class, args );
          }

          public static class MainFx extends Application
          {

              @Override
              public void start( final Stage primaryStage ) throws Exception
              {
                  final TreeView< Item > itemTreeView = new TreeView<>();
                  itemTreeView.setShowRoot( false );
                  itemTreeView.setRoot( createItems() );
                  itemTreeView.setFixedCellSize( 22 );
                  itemTreeView.setStyle( "-fx-background-color: red;" );

                  final BorderPane borderPane = new BorderPane( itemTreeView );
                  borderPane.setPadding( new Insets( 5 ) );
                  Scene scene = new Scene( borderPane, 800, 600 );
                  primaryStage.setScene( scene );
                  primaryStage.show();
              }

              private TreeItem< Item > createItems()
              {
                  final TreeItem< Item > root = new TreeItem<>( null );
                  root.getChildren().add( new TreeItem<>( new Item( "one" ) ) );
                  root.getChildren().add( new TreeItem<>( new Item( "two" ) ) );
                  root.getChildren().add( new TreeItem<>( new Item( "three" ) ) );
                  root.getChildren().add( new TreeItem<>( new Item( "four" ) ) );
                  root.getChildren().add( new TreeItem<>( new Item( "five" ) ) );
                  root.getChildren().add( new TreeItem<>( new Item( "six" ) ) );
                  root.getChildren().add( new TreeItem<>( new Item( "seven" ) ) );
                  return root;
              }

          }

          public static class Item
          {
              private final String text;

              public Item( final String aText )
              {
                  text = aText;
              }

              @Override
              public String toString()
              {
                  return text;
              }
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      TreeCellSkin has been patched, so minHeight, prefHeight, maxHeight respect snapSizeY:


          /** {@inheritDoc} */
          @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
              if (fixedCellSizeEnabled) {
                  return snapSizeY( fixedCellSize );
              }

              double pref = super.computeMinHeight(width, topInset, rightInset, bottomInset, leftInset);
              Node d = getSkinnable().getDisclosureNode();
              return (d == null) ? pref : Math.max(d.minHeight(-1), pref);
          }

          /** {@inheritDoc} */
          @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
              if (fixedCellSizeEnabled) {
                  return snapSizeY( fixedCellSize );
              }

              final TreeCell<T> cell = getSkinnable();

              final double pref = super.computePrefHeight(width, topInset, rightInset, bottomInset, leftInset);
              final Node d = cell.getDisclosureNode();
              final double prefHeight = (d == null) ? pref : Math.max(d.prefHeight(-1), pref);

              // RT-30212: TreeCell does not honor minSize of cells.
              // snapSize for RT-36460
              return snapSizeY(Math.max(cell.getMinHeight(), prefHeight));
          }

          /** {@inheritDoc} */
          @Override protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
              if (fixedCellSizeEnabled) {
                  return snapSizeY( fixedCellSize );
              }

              return super.computeMaxHeight(width, topInset, rightInset, bottomInset, leftInset);
          }


      FREQUENCY : always


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

              Created:
              Updated: