Run this snippet and see that the selectedProperty is never changing:
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.stage.Stage;
import javafx.util.Callback;
public class SimpleApp extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
TableView<String> view = new TableView<>();
TableColumn<String, String> col = new TableColumn<String, String>("Col");
col.setMinWidth(100);
col.setCellFactory(new Callback<TableColumn<String,String>, TableCell<String,String>>() {
@Override
public TableCell<String, String> call(TableColumn<String, String> param) {
return new TableCellImpl();
}
});
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<String,String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<String, String> param) {
System.err.println(param.getValue());
return new SimpleStringProperty(param.getValue());
}
});
view.getColumns().add(col);
view.setItems(FXCollections.observableArrayList("A","B","C"));
primaryStage.setScene(new Scene(view,300,300));
primaryStage.show();
}
static class TableCellImpl extends TableCell<String, String> {
public TableCellImpl() {
selectedProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
System.err.println("SELECTION CHANGED!!!!!");
}
});
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
}
}
}
Patch to follow
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.stage.Stage;
import javafx.util.Callback;
public class SimpleApp extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
TableView<String> view = new TableView<>();
TableColumn<String, String> col = new TableColumn<String, String>("Col");
col.setMinWidth(100);
col.setCellFactory(new Callback<TableColumn<String,String>, TableCell<String,String>>() {
@Override
public TableCell<String, String> call(TableColumn<String, String> param) {
return new TableCellImpl();
}
});
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<String,String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<String, String> param) {
System.err.println(param.getValue());
return new SimpleStringProperty(param.getValue());
}
});
view.getColumns().add(col);
view.setItems(FXCollections.observableArrayList("A","B","C"));
primaryStage.setScene(new Scene(view,300,300));
primaryStage.show();
}
static class TableCellImpl extends TableCell<String, String> {
public TableCellImpl() {
selectedProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
System.err.println("SELECTION CHANGED!!!!!");
}
});
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
}
}
}
Patch to follow