📜  如何监听 ObservableMap 上的更改 - 汇编代码示例

📅  最后修改于: 2022-03-11 14:48:10.079000             🧑  作者: Mango

代码示例1
import java.util.HashMap;
import java.util.Map;
/*from   www  .  j a  v a  2  s . co  m*/
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;

public class Main {

  public static void main(String[] args) {
    Map map = new HashMap();
    ObservableMap observableMap = FXCollections
        .observableMap(map);
    observableMap.addListener(new MapChangeListener() {
      @Override
      public void onChanged(MapChangeListener.Change change) {
        System.out.println("change! ");
      }
    });
    observableMap.put("key 1", "value 1");
    map.put("key 2", "value 2");

  }
}