Reputation: 19
I'm trying to create a custom control that stores a list of images. Ideally in the FXML file I could instantiate my control by passing an argument that is a list of file paths to said images.
I have gotten the control to load from FXML just fine here is the constructor
public Gallery(@NamedArg("images") List<String> images) {
this.imageQueue = new PriorityQueue<>(images);
this.load("gallery.fxml");
this.scrollImage();
}
Here is the FXML that loads it
<Gallery fx:id="contentPane" prefHeight="250.0" prefWidth="600.0">
<images>
1.png,
2.png,
3.png
</images>
</Gallery>
Loads without issue, but there are no images and doing some simple prints I see that instead of creating a list with three values of 1.png,2.png,3.png it creates a list with 1 value of "1.png, 2.png, 3.png"
So my question is how do I get this to instantiate as a list with 3 separate values in it?
Upvotes: 0
Views: 172
Reputation: 82461
A similar approach would work with readonly list properties, but there are pieces of information that are not provided with this kind of fxml:
List
should be used?"1.png,\n 2.png,\n 3.png"
, "1.png,", "\n 2.png,\n 3.png"
or something else?It is possible to do something like this, but you need to modify the structure of your fxml:
<?import java.util.ArrayList?>
<?import java.lang.String?>
...
<Gallery fx:id="contentPane" prefHeight="250.0" prefWidth="600.0">
<images>
<ArrayList>
<String fx:value="1.png" />
<String fx:value="2.png" />
<String fx:value="3.png" />
</ArrayList>
</images>
</Gallery>
Upvotes: 1