Copy constructors
Greg Brown
greg.x.brown at oracle.com
Mon Sep 10 10:28:27 PDT 2012
> I am not sure how an include would help much here. Consider this scenario:
>
> <fx:define>
> <GridPane fx:id="gp">...</GridPane>
> </fx:define>
>
> <VBox fx:id="vbox"/>
>
> Now, if I wanted to add N gridpanes much like the one from the define block as children of the vbox - in code, in a for loop, with some adjustments... how would I do this with fx:include?
You are correct - an include wouldn't help with this scenario. But neither would fx:copy, which is what I thought you were referring to. It seems you were referring to the copy constructor itself, which could be applied here.
> Thinking about it, there is not really even a need for a copy constructor which would deep-copy an otherwise useless template instance. It would be even better if the instantantion of the fx:define piece could be delayed, and would be repeatable in a loop:
>
> @FXML private VBox vbox;
>
> for (item: list) {
> GridPane gp = loader.instantiate("gp");
> customze(gp);
> vbox.getChildren().add(gp);
> }
Why not just partition the template contents into a separate FXML file and re-load it each time you need a new instance?
More information about the openjfx-dev
mailing list