Booleanbinding of multiple properties

Asked

Viewed 32 times

2

I made the following structure so that when I make one of the components invisible, the others follow the same configuration.

A.visibleProperty().bindBidirectional(B.visibleProperty()); 
A.visibleProperty().bindBidirectional(C.visibleProperty());
A.visibleProperty().bindBidirectional(D.visibleProperty());`

It works perfectly, however, I would like to find a way to do this more directly, example:

A.bindBidirectional(B.bindBidirectional(C));

something to that effect. If anyone knows how to help, please respond. Thank you.

1 answer

1

There is no way to do this since the object has several properties that can be linked, so A.bindBidirectional(B.bindBidirectional(C)) the class would not know which attribute it should link to. But to facilitate your work you can make a class that makes data connection.

public class BindUtil{
    public static void bindVisibleProperty(Node a, Node b){
        A.visibleProperty().bindBidirectional(B.visibleProperty()); 
    }

    ///... métodos que fazem  bind com outras propriedades
}

So just do it.

BindUtil.bindVisibleProperty(a, b);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.