javajavafxbeans-binding

Is it possible to bind with collection and if so how?


I have List<CheckBox>. I need to bind the selected property of them to a List<Boolean>. Is there any way to achieve it. If so how?


Solution

  • In Java 8 you can loop to the list with a stream:

    List<Boolean> booleans = 
        checkBoxList.stream().map(checkbox -> checkbox.isSelected()).collect(Collectors.toList());
    

    Of course, this not binding. It will copy the value to the new lists. If you change the values in booleans, it won't in the original checkBoxList object. boolean and Boolean are both immutable.

    Edit: Maybe your UI-Framework can handle List<.Checkbox> directly...