How to access a series of elements (gridpane type in my case) stored in an ObservableList

1

I have 5 GridPane that I need to make visible / invisible depending on certain circumstances. I have tried to store them in an ObservableList but when trying to access them to apply the method .setVisible gives error, since when accessing the index it returns null instead of the gridpane in question. Porfa Help: (

@FXML
private GridPane fila1;
@FXML
private GridPane fila2;
@FXML
private GridPane fila3;
@FXML
private GridPane fila4;
@FXML
private GridPane fila5;

@FXML
ObservableList<GridPane> mesas = FXCollections.observableArrayList(fila1,fila2,fila3,fila4,fila5);

for(int i=0;i<temp.getEmpleados().size();i++) {
    mesas.get(i).setDisable(false);
    }
    
asked by juakiz 08.05.2016 в 23:08
source

1 answer

1

The elements of the collection are perfectly accessible. Possibly your error is because you try to access with an index out of range, that is, an 'i' higher than the amount of GridPane of ObservableList . I do not know what temp.getEmpleados() is, so I'll call it 'element'. The for loop would be something like this:

mesas.stream().forEach((elemento) -> {
    elemento.setDisable(false);
        });
    
answered by 09.05.2016 / 21:05
source