-
Notifications
You must be signed in to change notification settings - Fork 145
I cannot start JavaFX app with images in FXML in a modular project #441
Comments
We are not aware of any problem that this is causing. If you believe that you have found a bug, then please provide a complete, standalone test program that demonstrates it. If you would like to contribute a fix, even better. Please read CONTRIBUTING.md for instructions on how to proceed. |
You need to
But it's not. Maybe @kevinrushforth could shine some light on that. My guess is, since the resource's package must be opened to at least the caller, that it's simply an issue of who's actually the caller in this case. If you don't want to
This will result in using a valid URL for the Note: The same issue applies to CSS files and |
Thanks, prefixing with "@" works, but with it all my icon references become like "@../../images/...", which is not very satisfying. Opening a package also works, and I think it is perfect for me, because all images are confined in a separate package. It would be nice if the documentation is updated to mention this special treatment of Images inside FXML. |
This does seem like something that would be good to document. We already document that you need to open your package to Before I file the doc bug, could you also test whether opening your package to both javafx.fxml and javafx.graphics works? If so, that would seem preferable to using
|
Just tested it. Unfortunately, qualified opens does not seem to work.
Which is still OK for me, since these packages contain only images/styles. |
This seems like a bug, probably similar in nature to JDK-8177566. I'll file a JBS bug to track this. The workaround, as you discovered, is to unconditionally open the package containing your images. |
Want to point out that this isn't just an issue with FXML. Trying to use a resource path programmatically doesn't work either, unless you
However, I don't know if there's an elegant way to fix this problem. Especially a fix that will work for both. The In which case, I think the only option is to Please note, however, that I am not an expert in the module system. I bring this up as a potential issue in the first place because both |
Oh, I see. You are right that this isn't the same case as the FXML case, where it was an internal "trampoline" class running in the unnamed module that caused the problem. I'll still take a closer look, but this may well end up being something to document rather than a bug to fix. |
@kevinrushforth any updates on this issue? While trying to convert my large project over to modules, I got stuck on this exact same thing. However in my case, the resources in question lived in a different .jar file of their own, which I was adding to the modular project using --patch-module. I don't know how to use --add-opens to create an unqualified opens (it's impossible, right?). So I believe I'll be forced to rearrange my project build so that the resources are in a .jar file which also has a module-info. I hope that this bug can get fixed in a way that helps avoid that kind of roadblock. |
When an OpenJFX app uses Java 11 module system and UI is loaded from FXML that contains Images with URLs, it cannot be started. The reason is in this code in javafx/scene/image/Image.java:
Fix this already! It has been ages since Java 9 is released, and you still have these FIXMEs ?
This is a major issue, you cannot start the app from the IDE, nor a user can start the app with standard Java 11 options for modular apps (--module-path and --module).
I even can fix it myself if you give me authorization to do so.
The text was updated successfully, but these errors were encountered: