I'm adding my application icon with stage.getIcons().add(new Image("path"))
and the icon will appear sometimes, so I know that the program can find the resource and I'm calling the right methods, but the icon won't appear every time. From what I can tell from this question this is probably because swing (which I believe JavaFX uses) loads images in a separate thread. If this is the problem, how can I ensure that loading and adding the icon finishes before I call stage.show()? If this is not the problem, what is going on here and what am I doing wrong? I'm using JRuby so your answer can include Ruby libs if they're applicable. A purely Java answer is fine too.
Asked
Active
Viewed 266 times
1
-
By making the icon add the very first line in my start method, I was able to get it working all the time. This is only, presumably, because I had enough methods between `stage.getIcons().add` and `stage.show()` that gave time for the image to load. Its not really a solution. – griest May 29 '15 at 00:28
-
This question has some incorrect assumptions. JavaFX 8 does not use Swing. A JavaFX Image is loaded synchronously, not asynchronously (unless you explicitly set a [background loading flag in the Image constructor](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/Image.html#Image-java.lang.String-double-double-boolean-boolean-boolean-) - which you don't do). I cannot reproduce your issue using a pure Java application. – jewelsea Jul 07 '15 at 20:03
1 Answers
0
Hello I think that the program process that loads the image does did not finish loading before you are showing it. You can add a wait()
function after your icon addition. Or you can execute another function in between your add(new Image("pokemon.png"))
and your primaryStage.show()
this will ensure that your image load will finish before you show the stage.