I have tried to find my answer on google but no results right now.
So i'm sorry if its an already solved post.
What I want to do : When my FXML file is load, I want the imageView in this file to load an image from an URL which is contain in a table of Strings who contains differents URLs, so I can switch the image on load according to my choice
variable. I have tried with absolute paths and relative paths.
In my main :
//url tab of the 2 images
public static String[] images = new String[2];
//variable that include the choice for the image to load in the tab images
public static int choice = 0;
public MainTest() {
images[0] = "C:/Users/Stagiaire ACI/Desktop/Java/ImageTestImage/Assasin.png";
images[1] = "C:/Users/Stagiaire ACI/Desktop/Java/ImageTestImage/Barde.png";
}
My fxml file controler :
@FXML
private ImageView image;
@FXML
private void initialize() {
Image image = new Image(MainTest.images[MainTest.choice]);
this.image.setImage(image);
}
And my Fxml file :
<AnchorPane prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.test.view.TestControler">
<children>
<ImageView fx:id="image" fitHeight="310.0" fitWidth="319.0" layoutX="306.0" layoutY="183.0" pickOnBounds="true" preserveRatio="true" />
</children>
</AnchorPane>
So with this i can change choice
to change the image on load.
My images works well when I load it with the classic way.
Don't even know if it's possible.
Thank you!
EDIT : I have solved my problem by putting file:
above the file url.