JavaFX: Add an image to the GridPane

你。 提交于 2019-12-25 05:14:24

问题


I want to put an Image into a GridPane.

The URI ist existant, I imported javafx.scene.image, I declared everything. Why does it not work? It just gives me a blank window. Even with a local picture its not working. And when I for example write something like "file:sdhasidf.png" (Not existant btw.), its just a blank window, too. I'm just getting a UnknownProtocol Exception if I mess up the protocol, so it gets loaded.

Image img = new Image("https://cdn.discordapp.com/attachments/250163910454280192/296377451599364107/Untitled.png");
ImageView imgView = new ImageView(img);

GridPane.setConstraints(imgView, 5, 0);
gp.getChildren().add(imgView);  //gp ist a GridPane

Scene scene = new Scene(gp, 500, 600);
window.setScene(scene);
window.show();

Thanks for reading :)

来源:https://stackoverflow.com/questions/43250901/javafx-add-an-image-to-the-gridpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!