/**
 * Testcase for incident report 9105420 
 * 
 * to show the error: Start the application and do not resize the stage. The right trough will be too small.
 *                    If the stage is resized to a height greater than the table row's height, the trough will be big enough.
*/
package sample;

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.util.Callback;

public class SampleApp extends Application
   {
   public static void main( String[] args )
      {
      launch( args );
      }

   @Override
   public void start( Stage primaryStage )
      {
      primaryStage.setTitle( "TableView Test" );
      TableColumn<TableEntry, String> col = new TableColumn<>( "First Name" );

      TableView<TableEntry> table = new TableView<TableEntry>();
      table.getColumns().addAll( col );
      table.getItems().addAll( new TableEntry( "First" ), new TableEntry( "Second" ), new TableEntry( "Third" ) );
      col.setCellValueFactory( new PropertyValueFactory<TableEntry, String>( "name" ) );

      col.setCellFactory( MyCellFactory.forTableColumn() );

      StackPane root = new StackPane();
      root.getChildren().add( table );
      primaryStage.setScene( new Scene( root, 800, 250 ) );
      primaryStage.show();
      }

   public static class TableEntry
      {
      StringProperty name = new SimpleStringProperty();

      public TableEntry( String name )
         {
         this.name.set( name );
         }

      public String getName()
         {
         return name.get();
         }

      public void setName( String name )
         {
         this.name.set( name );
         }
      }

   public static class MyCellFactory extends TableCell<TableEntry, String>
      {
      public MyCellFactory()
         {
         setFont( new Font( "Times New Roman", 192 ) );
         }

      @Override
      protected void updateItem( String item, boolean empty )
         {
         super.updateItem( item, empty );
         if( empty || item == null )
            {
            setText( null );
            return;
            }
         setText( item );
         }

      public static Callback<TableColumn<TableEntry, String>, TableCell<TableEntry, String>> forTableColumn()
         {
         return e -> new MyCellFactory();
         }

      }
   }