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

TableCell#selectedProperty does not update

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:

      Description

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              tschindl Tom Schindl
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported: