Hi,
I am not sure, how Bindings.bindContent() is intended to work with 2 lists, but I expected, that both lists always contain the same elements.
However, if I sort the source list (second parameter), and then remove an item from it (or alter the list in another way), the target list (first parameter) no longer contains the same elements, as the first list.
See this example:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) throws Exception {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
ObservableList<String> list1 = FXCollections.observableArrayList("BBB", "CCC", "AAA");
ObservableList<String> list2 = FXCollections.observableArrayList();
Bindings.bindContent(list2, list1);
FXCollections.sort(list1);
list1.remove("BBB");
System.out.println(list1);
System.out.println(list2);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
I am not sure, how Bindings.bindContent() is intended to work with 2 lists, but I expected, that both lists always contain the same elements.
However, if I sort the source list (second parameter), and then remove an item from it (or alter the list in another way), the target list (first parameter) no longer contains the same elements, as the first list.
See this example:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TestApp3 extends Application {
public static void main(String[] args) throws Exception {
launch(args);
}
public void start(final Stage stage) throws Exception {
VBox root = new VBox();
ObservableList<String> list1 = FXCollections.observableArrayList("BBB", "CCC", "AAA");
ObservableList<String> list2 = FXCollections.observableArrayList();
Bindings.bindContent(list2, list1);
FXCollections.sort(list1);
list1.remove("BBB");
System.out.println(list1);
System.out.println(list2);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}