0

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.

3
  • minimal reproducible example please .. Commented Apr 24, 2023 at 11:20
  • 3
    Never set something annotated @FXML to a new value. Commented Apr 24, 2023 at 11:25
  • As noted, never reassign an @FXML-annotated field. Such fields are injected with the instance displayed in the UI by the FXMLLoader. If you reassign one then you lose access to that instance. You should probably be doing something like homeTeamLogo.setImage(image). Commented Apr 24, 2023 at 17:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.