Open Image from FileChooser in JavaFX

强颜欢笑 提交于 2019-12-01 11:54:18

The problem is that the constructor of Image is expecting a String url, whereas you're passing it a File. Any good IDE will tell you what a given method is expecting as its parameters; find that keyboard shortcut and use it (Ctrl + P in IntelliJ). From there, all you have to do is find a way to convert a File to a Stringrepresenting its url. In this case:

Image image1 = new Image(file.toURI().toString());

Note that you are never actually setting your background image, you need to add the following line to your lambda:

stac.setBackground(new Background(backgroundImage));

For this though, you will have to move the declaration of stac above your action listener.

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