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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Environment:

      Ubuntu 64,
      Java (build 1.8.0_20-ea-b11

      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

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: