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

Initial column autosizing does not take graphics into computing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx11, jfx20, jfx17, jfx18, jfx19
    • javafx
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.18363.1198]
      openjdk version "11.0.5" 2019-10-15
      OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Initial column autosizing does not take graphics into computing pref width of column header.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open provided test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Column header text should be fully visible.
      ACTUAL -
      Column header is shortened on initial table show, double click on column header reorder line makes autosize works good and fit the header graphics.

      ---------- BEGIN SOURCE ----------
      import java.util.Map;
      import java.util.stream.Collectors;
      import java.util.stream.IntStream;

      import javafx.application.Application;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.control.cell.MapValueFactory;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class GraphicsInHeaderColumnTest
      {

          public static void main( String[] args )
          {
              Application.launch( FxApp.class, args );
          }

          public static class FxApp extends Application
          {

              @Override
              public void start( final Stage primaryStage ) throws Exception
              {
                  System.err.println( System.getProperty( "javafx.version" ) );
                  final var rootPane = new HBox( 5d );
                  final TableView< Map< String, Object > > tableView = createTableView();
                  rootPane.getChildren().add( tableView );

                  final TreeTableView< Map< String, Object > > treeTableView = createTreeTableView();
                  rootPane.getChildren().add( treeTableView );

                  primaryStage.setScene( new Scene( rootPane, 800, 600 ) );
                  primaryStage.show();
              }

              private TreeTableView< Map< String, Object > > createTreeTableView()
              {
                  final TreeTableView< Map< String, Object > > treeTableView = new TreeTableView<>();
                  treeTableView.setShowRoot( false );
                  final TreeItem< Map< String, Object > > root = new TreeItem<>();
                  for( int i = 0; i < 10; i++ )
                  {
                      final Map< String, Object > data = Map.of( "id", i, "data", "row" + i );
                      final TreeItem< Map< String, Object > > treeItem = new TreeItem<>( data );
                      root.getChildren().add( treeItem );
                  }
                  final var idCol = new TreeTableColumn< Map< String, Object >, Object >( "id" );
                  idCol.setCellValueFactory( param -> {
                      final var value = param.getValue();
                      if( value == null || value.getValue() == null )
                      {
                          return null;
                      }
                      return new SimpleObjectProperty<>( value.getValue().get( "id" ) );
                  } );
                  idCol.setText( null );
                  idCol.setGraphic( new Label( "Long text 'id'" ) );

                  final var dataCol = new TreeTableColumn< Map< String, Object >, Object >( "data" );
                  dataCol.setCellValueFactory( param -> {
                      final var value = param.getValue();
                      if( value == null || value.getValue() == null )
                      {
                          return null;
                      }
                      return new SimpleObjectProperty<>( value.getValue().get( "data" ) );
                  } );
                  dataCol.setText( null );
                  dataCol.setGraphic( new Label( "Long text 'data'" ) );
                  treeTableView.getColumns().addAll( idCol, dataCol );
                  treeTableView.setRoot( root );
                  return treeTableView;
              }

              private TableView< Map< String, Object > > createTableView()
              {
                  final TableView< Map< String, Object > > tableView = new TableView<>( FXCollections
                      .observableArrayList( IntStream.range( 0, 10 )
                          .mapToObj( i -> Map.< String, Object >of( "id", i, "data", "row_" + i ) )
                          .collect( Collectors.toList() ) ) );
                  final var idCol = new TableColumn< Map, Object >( "id" );
                  idCol.setCellValueFactory( new MapValueFactory< Object >( "id" ) );
                  idCol.setText( null );
                  idCol.setGraphic( new Label( "Long text 'id'" ) );

                  final var dataCol = new TableColumn< Map, Object >( "data" );
                  dataCol.setCellValueFactory( new MapValueFactory< Object >( "data" ) );
                  dataCol.setText( null );
                  dataCol.setGraphic( new Label( "Long text 'data'" ) );
                  tableView.getColumns().add( (TableColumn)idCol );
                  tableView.getColumns().add( (TableColumn)dataCol );
                  return tableView;
              }

          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      run autosizing for all columns after it is shown

            Unassigned Unassigned
            pnarayanaswa Praveen Narayanaswamy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: