Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8127046

Bindings.bindContent() does not properly work for lists, when you sort one list.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • fx2.1
    • javafx
    • 2.1 b08

      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();
          }
      }

            mheinrichs Michael Heinrichs (Inactive)
            cschudtjfx Christian Schudt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: