是否可以在JavaFX中创建动态Bindings.OR?

是否可以在JavaFX中创建动态Bindings.OR?,第1张

是否可以在JavaFX中创建动态Bindings.OR?

您可以按照以下方式尝试 *** 作

// list that fires updates if any members change visibility:ObservableList<Node> children =     FXCollections.observableArrayList(n -> new Observable[] {n.visibleProperty()});// make the new list always contain the same elements as the pane's child list:Bindings.bindContent(children, parentPane.getChildren());// filter for visible nodes:ObservableList<Node> visibleChildren = children.filter(Node::isVisible);// and now see if it's empty:BooleanBinding someVisibleChildren = Bindings.isNotEmpty(visibleChildren);// finally:parentPane.visibleProperty().bind(someVisibleChildren);

另一种方法是

BooleanBinding
直接创建自己的:

Pane parentPane = ... ;BooleanBinding someVisibleChildren = new BooleanBinding() {    {        parentPane.getChildren().forEach(n -> bind(n.visibleProperty()));        parentPane.getChildren().addListener((Change<? extends Node> c) -> { while (c.next()) {    c.getAddedSubList().forEach(n -> bind(n.visibleProperty()));    c.getRemoved().forEach(n -> unbind(n.visibleProperty())) ; }        });        bind(parentPane.getChildren());    }    @Override    public boolean computevalue() {        return parentPane.getChildren().stream() .filter(Node::isVisible) .findAny() .isPresent();    }}parentPane.visibleProperty().bind(someVisibleChildren);


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5141797.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-17
下一篇2022-11-17

发表评论

登录后才能评论

评论列表(0条)

    保存