import javafx.application.Application; 
import javafx.beans.property.Property; 
import javafx.beans.property.SimpleStringProperty; 
import javafx.collections.ListChangeListener; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

import java.io.IOException; 
import java.util.stream.Collectors; 
import java.util.stream.Stream; 

/** 
 * Launch app, select first row and then press button. Selection event erroneously returns 
 * full TableView list instead of selected item list. 
 */ 
public class TestApplication extends Application { 
public static void main(String[] pArgs) {launch(pArgs);} 

@Override public void start(Stage pStage) throws IOException { 
Thread.setDefaultUncaughtExceptionHandler( 
(pThread, pThrowable) -> pThrowable.printStackTrace() 
); 

        final TableView<Property<String>> tableView = new TableView<>(); 
        final TableColumn<Property<String>,String> col = new TableColumn<>("Col"); 
        col.setCellValueFactory(TableColumn.CellDataFeatures::getValue); 
        tableView.getColumns().add(col); 
        tableView.getItems().addAll( 
            Stream.of("alpha", "bravo", "charlie").map(SimpleStringProperty::new).collect( 
                Collectors.toList() 
            ) 
        ); 

        tableView.getSelectionModel().getSelectedItems().addListener( 
            (ListChangeListener<Property<String>>) change -> System.out.println( 
                "New selection: " + change.getList() 
            ) 
        ); 

        final Button btn = new Button("update content"); 
        btn.setOnMouseClicked( 
            event -> tableView.getItems().setAll( 
                Stream.of("delta", "echo", "foxtrot").map(SimpleStringProperty::new).collect( 
                    Collectors.toList() 
                ) 
            ) 
        ); 

pStage.setTitle("Test"); 
pStage.setScene(new Scene(new VBox(tableView, btn), 400, 300)); 
pStage.show(); 
} 
} 
