JavaFx:如何在应用程序运行时观察Anchorpane?

时间:2017-05-29 08:35:21

标签: java javafx javafx-2 javafx-8

如何使用observable或binding来检查内部anchorpane是否存在某个节点现在我正在使用if语句:

RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^pages\.example\.com$ [NC]
RewriteRule ^ https://example%{REQUEST_URI}  [R=301,L,NE]

我想实现这一点,因为if(anchorPane().getChildren().size()>0){ GridPane table = (GridPane) anchorPane().getChildren().get(0); for(int i=1 ; i<=ComboBox().getValue(); i++){ TextField Text0 = ((TextField)getComponent (i, 0, table)); TextField Text1 = ((TextField)getComponent (i, 1, table)); TextField Text2 = ((TextField)getComponent (i, 2, table)); TextField Text3 = ((TextField)getComponent (i, 3, table)); TextField Text4 = ((TextField)getComponent (i, 4, table)); TextField Text5 = ((TextField)getComponent (i, 5, table)); TextField Text6 = ((TextField)getComponent (i, 6, table)); TextField Text7 = ((TextField)getComponent (i, 7, table)); System.out.println(Text0 + " " + Text1 + " " + Text2 + " " + Text3 + " " + Text4 + " " + Text5 + " " + Text6 + " " + Text7); } } 并不总是保持0,它会在应用程序运行状态期间发生变化。

1 个答案:

答案 0 :(得分:0)

您可以为可观察列表是否为空创建布尔绑定:

BooleanBinding empty = Bindings.isEmpty(anchorPane.getChildren());

然后:

empty.addListener((obs, wasEmpty, isNowEmpty) -> {
    if (! isNowEmpty) {
        // ...
    }
});