0

I am wondering how can I create an array of Containers in Javafx.

What I mean is I like to create for loop, and inside I will create Panes and labels inside each Pane created.

for(int i=0;i<10;i++){ // I will create 10 Panes with each one has 4 labels in it. }

The thing is I have googled it and checked here as well, but couldnt see any example for this.

Can anyone help me with the logic of this.

Thanks

  • well actually when I creating the Pane objects it doesnt show up and giving error. here is what have I done in the controller. ` @FXML Pane[] listPane = new Pane[5];` and ` @FXML public void paneTest(){ for(int i=0;i<5;i++){ listPane[i].setStyle("-fx-background-color: black;"); listPane[i].setPrefSize(200,200); }` and I get this error `Jan 22, 2017 11:45:22 PM com.windows.scene.MenuTest1Controller listReceipts SEVERE: null javafx.fxml.LoadException: ` – David Green Jan 22 '17 at 23:46
  • @FXML Pane[] listPane = new Pane[5] <- don't do this. – SedJ601 Jan 23 '17 at 01:52
  • If you have 5 Panes you created with FXML you should do something like this. @FXML Pane your1stFXMLPane, your2ndFXMLPane, ...; Also do Pane[] listPane = new Pane[5]. Then in your ini method do: listPane[0] = your1stFXMLPane; listPane[1] = your2ndFXMLPane; ... – SedJ601 Jan 23 '17 at 01:56

0 Answers0