Image files are easy to load if you place them in the same package as your code. Given that, an example like the following will do the trick:
import javafx.fxml.FXML; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.Pane; public class Controller { @FXML private Pane pane; private ImageView img; @FXML void initialize() { img = new ImageView(new Image(Controller.class.getResourceAsStream("Screen.png"))); pane.getChildren().add(img); } }
No comments:
Post a Comment