package com.ecrsoft.common.javafx; import java.util.ArrayList; import java.util.List; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class App extends Application { public static void main( String[] args ) { Application.launch( App.class, args); } @Override public void start(Stage stage) throws Exception { VBox vbox = new VBox( 5); final TableView table = new TableView(); table.setItems( FXCollections.observableArrayList()); table.setFocusTraversable( false); table.getSelectionModel().setCellSelectionEnabled( false); table.getSelectionModel().setSelectionMode(SelectionMode.SINGLE_SELECTION); table.setColumnResizePolicy( TableView.UNCONSTRAINED_RESIZE_POLICY); TableColumn nameColumn = new TableColumn( "Name"); nameColumn.setSortable( false); nameColumn.setProperty( "Name"); table.getColumns().setAll( nameColumn); Button button = new Button( "Add Items"); button.setOnAction( new EventHandler() { @Override public void handle(ActionEvent t) { table.getItems().setAll( addToList( 2, new ArrayList( table.getItems()))); //table.getSelectionModel().select( table.getItems().size()-1); //table.scrollTo( table.getItems().size()-1); } }); vbox.getChildren().setAll( table, button); Scene scene = new Scene( vbox, 100, 200); stage.setScene( scene); stage.setVisible( true); } private List addToList( int quantity, List dataList) { int originalSize = dataList.size(); for( int i = originalSize; i < originalSize + quantity; i++) { dataList.add( new Data( "Item " + i)); } return dataList; } public static final class Data { private final String name; public Data( String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { return name; } } }