JavaFX SortedList: прослушивание изменений списка и события обновленных элементов списка

Случай использования:

упорядоченный ListView (или TableView)вставки сделаны после показаобновления ключей производятся после отображения

Список при запуске:

После добавления 18:

После обновления:

Как видите, ничего не меняется!

Код:

public final class SortedListTest extends Application {

   @Override
   public void start( Stage stage ) throws Exception {
      final ObservableList<IntegerProperty> il =
         FXCollections.observableArrayList();
      il.add( new SimpleIntegerProperty( 12 ));
      il.add( new SimpleIntegerProperty( 24 ));
      il.add( new SimpleIntegerProperty( 36 ));
      final Button add    = new Button( "Add 18" );
      final Button update = new Button( "Update 24 to 8" );
      final HBox   ctrl   = new HBox( 4.0, add, update );
      final ListView<IntegerProperty> listVw =
         new ListView<>( new SortedList<>( il, (l,r)-> l.get() - r.get()));
      stage.setScene(
         new Scene(
            new BorderPane( listVw, ctrl, null, null, null ), 180, 120 ));
      stage.show();
      add.setOnAction( e -> {
         il.add( new SimpleIntegerProperty( 18 ));
         System.err.println( "--------------" );
         il.stream().forEach( System.err::println );
      });
      update.setOnAction( e -> {
         il.get( 1 ).set( 8 );
         System.err.println( "--------------" );
         il.stream().forEach( System.err::println );
      });
   }

   public static void main( String[] args ) {
      launch( args );
   }
}

Приставка:

--------------
IntegerProperty [value: 12]
IntegerProperty [value: 24]
IntegerProperty [value: 36]
IntegerProperty [value: 18]
--------------
IntegerProperty [value: 12]
IntegerProperty [value: 8]
IntegerProperty [value: 36]
IntegerProperty [value: 18]

Мы видим, что модель корректно обновлена, но не вид, почему?

Рабочий пример

(После принятия очень простого, но хорошего ответа James_D :)

Вот полный пример с записью свойств для иллюстрации решения:

public final class SortedListTest extends Application {

   class Record {

      final IntegerProperty _key   = new SimpleIntegerProperty();
      final StringProperty  _value = new SimpleStringProperty();

      Record( int k, String v ) {
         _key  .set( k );
         _value.set( v );
      }

      @Override
      public String toString() {
         return "Key = " + _key.get() + ", value = " + _value.get();
      }
   }

   @Override
   public void start( Stage stage ) throws Exception {
      final ObservableList<Record> il =
         FXCollections.observableArrayList(
            rec -> new Observable[]{ rec._key });
      il.add( new Record( 12, "Douze" ));
      il.add( new Record( 24, "Vingt quatre" ));
      il.add( new Record( 36, "Trente six" ));
      final Button add    = new Button( "Add 18" );
      final Button update = new Button( "Update 24 to 8" );
      final HBox   ctrl   = new HBox( 4.0, add, update );
      final SortedList<Record> sortedList =
         il.sorted((l,r)-> Integer.compare(l._key.get(), r._key.get()));
      final ListView<Record> listVw = new ListView<>( sortedList );
      stage.setScene( new Scene(
         new BorderPane( listVw, ctrl, null, null, null ), 200, 140 ));
      stage.show();
      add.setOnAction( e -> {
         il.add( new Record( 18, "Dix huit" ));
         System.err.println( "--------------" );
         il.stream().forEach( System.err::println );
      });
      update.setOnAction( e -> {
         il.get( 1 )._key.set( 8 );
         System.err.println( "--------------" );
         il.stream().forEach( System.err::println );
      });
   }

   public static void main( String[] args ) {
      launch( args );
   }
}

И результат:

Ответы на вопрос(1)

Ваш ответ на вопрос