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

[TableView] Adding an Item throws a ChangeEvent to the selectedItemProperty

    XMLWordPrintable

Details

    Description

      Hello,

      after adding an Item to a TableView the ChangeListeners are called two times

      Look at this code and the output:

      TableView<Integer> tv = new TableView<>();
      tv.getItems().add(1);
      tv.getSelectionModel().select(0);

      tv.getSelectionModel().selectedItemProperty()
      .addListener(new ChangeListener<Object>() {
      @Override
      public void changed(
      ObservableValue<? extends Object> observable,
      Object oldValue, Object newValue) {
      System.out.println("OLDVALUE: " + oldValue
      + " NewValue: " + newValue);
      }
      });
      tv.getItems().add(2);


      Output:

      OLDVALUE: 1 NewValue: null
      OLDVALUE: null NewValue: 1

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: