I build desktop app in JavaFX and Spring (net.rgielen). I use one of RapidAPI API. I am trying to display an image with a URL provided with this API (for example: https://tipsscore.com/resb/team/fiorentina.png), but it does not work. The image is not displayed. My piece of Java code:
@FXML
private ImageView homeTeamLogo;
...
String url = "https://tipsscore.com/resb/team/fiorentina.png";
Image image = new Image(url);
homeTeamLogo = new ImageView(image);
And a FXML element:
<fx:root prefHeight="200.0" prefWidth="400.0" type="javafx.scene.control.ListCell" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<graphic>
<AnchorPane>
<ImageView fx:id="homeTeamLogo" fitHeight="82.0" fitWidth="77.0" layoutX="33.0" layoutY="40.0" pickOnBounds="true" preserveRatio="true" />
</AnchorPane>
</graphic>
</fx:root>
I tried this solution: JavaFX - image url not loading
but didn`t help.
@FXML-annotated field. Such fields are injected with the instance displayed in the UI by theFXMLLoader. If you reassign one then you lose access to that instance. You should probably be doing something likehomeTeamLogo.setImage(image).