Bind Parent to a Observable List


I want to bind the VBox.getChildren() ObservableList to my own ObservableList. So that, when ever my process detects an Image, it is added to my list which in turn automatically is added to the VBox.


It throws the below exception:

Exception in thread "Thread-3" java.lang.UnsupportedOperationException

Is there any other way of doing it? What is the issue above?

2/5/2013 10:28:20 AM

Accepted Answer

It's not a problem with binding, your approach is correct. You may be getting UnsupportedOperationException due to older versions of FX.

E.g. next example works for me using 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));;
2/5/2013 12:32:53 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow