2013-02-05 26 views
4

我想将VBox.getChildren()ObservableList绑定到我自己的ObservableList。所以,当我的进程检测到图像时,它会被添加到我的列表中,然后它会自动添加到VBox中。将父代绑定到可观察列表

Bindings.bindContentBidirectional(myList,vbox.getChildren()); 

它抛出以下异常:在线程

例外 “线程3” java.lang.UnsupportedOperationException

有没有做任何其他方式?以上问题是什么?

回答

7

这不是绑定的问题,您的方法是正确的。由于较旧版本的FX,您可能获得UnsupportedOperationException

E.g.下一个例子适用于我使用JavaFX 2.2:

public void start(Stage primaryStage) { 
    ObservableList<Node> list = FXCollections.<Node>observableArrayList(); 
    VBox root = new VBox(); 

    Bindings.bindContentBidirectional(list, root.getChildren()); 
    list.add(new Button("Test")); 

    primaryStage.setScene(new Scene(root, 300, 250)); 
    primaryStage.show(); 
}