簡體   English   中英

JavaFx:如何在應用程序運行時觀察Anchorpane?

[英]JavaFx: How to observe Anchorpane while application is running?

如何檢查錨板內部是否存在某些節點,或者現在不使用可觀察或綁定的方式,我正在使用if語句,如下所示:

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

            }
    }

我想要實現這一點,因為anchorPane().getChildren().size()不會始終保持為0,它將在應用程序的運行狀態期間發生變化。

您可以為可觀察列表是否為空創建布爾綁定:

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

接着:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM