2017-05-29 2 views
0

Comment vérifier si l'intérieur anchorpane il y a un noeud existent ou non observables ou en utilisant la liaison en ce moment j'utilise instruction if comme ceci:JavaFx: Comment observer Anchorpane pendant que l'application est en cours d'exécution?

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

      } 
    } 

Je veux atteindre parce que anchorPane().getChildren().size() ne restera pas toujours 0, cela va changer pendant l'état de fonctionnement de l'application.

Répondre

0

Vous pouvez créer une liaison de booléenne pour savoir si une liste observable ou non est vide:

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

Et puis:

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