JavaFX ObservableMap handle change event

Description

JavaFX ObservableMap handle change event

import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;

public class Main {
  public static void main(String[] args) {
    // Create an observable map and add two key-value pairs to the map
    ObservableMap<String, Integer> map = FXCollections.observableHashMap();
    map.put("one", 1);
    map.put("two", 2);

    map.addListener((MapChangeListener.Change<? extends String,
        ? extends Integer> change) -> {
      System.out.println("The map has changed.");
    });//  ww  w . j av  a 2  s.  com

  }
}



PreviousNext

Related