-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaFX extension #9313
JavaFX extension #9313
Comments
Seems that JavaFX does work in native mode: https://gluonhq.com/native-windows-applications-using-gluon-substrate-javafx-and-graalvm/ |
Yes. This issue is about having cdi injection between javafx models / controllers. |
👍 I would love to look into it, but I dont know when I'll be able to... |
Although it might be really easy, won't really know until / unless I look into it |
I removed the
|
Another issue is the use of FXML and how the FXMLLoader uses reflection on the generated CDI controller proxies if the controller is not using Dependent scoping. Ideally a CDI aware FXMLLoader would be produced that does not use reflection, but it did not look possible to do with a simple subclass of FXMLLoader given the current architecture. |
FXML strongly depends on reflection, but I am very open to discuss how we can avoid this (without breaking the top-level API). I agree CDI would be interesting here. |
I've been investigating this a little bit.. |
For FXML, I think we could generate a custom implementation of FXMLLoader. We would need to generate custom classes for all fxml files, and the FXMLLoader simple construct instances of the generated class for the corresponding FXML files. There is the issue that FXMLLoader can load via an InputStream, so we would need to keep the entire fxml file in memory so we can map the input stream to an instance. |
I created a simple demo with minimal implementation, see https://github.com/pedrolopix/quarkus-javafx-example |
Nice @pedrolopix ! |
Haven't been at laptop where I can run it but from reading code I assume this is only jvm mode and injection is not happening in the jfx application side - correct ? |
Yes it's correct, it's only jvm mode and no injection in jfx side. It's only a simple example, better than nothing :) |
Definitely! Very appreciated. |
Nice @pedrolopix ! But I can't debug, when click button it throw null pointer! |
Just open the pom.xml in intellij as a project, then start CDIApplication.main as a debug, it should work. |
Perfect @pedrolopix ! Many thanks !!! |
@pedrolopix based on your example (thanks!) I got it working for my application with latest quarkus on java 16 and jfx 17.0.0.1. But it works with jar only. ( 2021-09-17 13:35:10,901 ERROR [com.acme.app.JavaFxApp] (JavaFX Application Thread) Do exit due to error: java.lang.InternalError: bouncer cannot be found
at com.sun.javafx.reflect.MethodUtil.getTrampoline(MethodUtil.java:312)
at com.sun.javafx.reflect.MethodUtil.<clinit>(MethodUtil.java:87)
at com.sun.javafx.fxml.BeanAdapter.getStaticSetterMethod(BeanAdapter.java:924)
at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:583)
at javafx.fxml.FXMLLoader$PropertyElement.set(FXMLLoader.java:1429)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:801)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2924)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2639)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2532)
at com.acme.app.JavaFxApp.start(JavaFxApp.java:40)
at com.acme.app.app.JavaFxApp_Observer_start_3258073454a8dd2db56a11c729e58aa8381e7513.notify(JavaFxApp_Observer_start_3258073454a8dd2db56a11c729e58aa8381e7513.zig:153)
at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:307)
at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:289)
at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:70)
at io.quarkus.arc.impl.BeanManagerImpl.fireEvent(BeanManagerImpl.java:122)
at com.acme.app.app.FxApplication.start(FxApplication.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:290)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Class.getDeclaredMethod(String, java.lang.Class[])" because "<local1>" is null
at com.sun.javafx.reflect.MethodUtil$1.run(MethodUtil.java:306)
at com.sun.javafx.reflect.MethodUtil$1.run(MethodUtil.java:300)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at com.sun.javafx.reflect.MethodUtil.getTrampoline(MethodUtil.java:299)
... 24 more Any ideas why does it work in jar mode but not with maven? |
Just bumped the demo project to latest versions and work fine |
@pedrolopix I pulled your changes and get the same error when pressing 'Click' button with
|
I used a similar approach but required a vm option for the maven javafx plugin. |
any update here ? SORRY for my bad english. |
@moamenhredeen I haven't had time to look deeper. If you want to help go try and make JavaFX based example and see how far you get. As mentioned above running JavaFX in quarkus app is all doable as it is "just java" - what needs solving is how we get Arc dependency injection happening in a JavaFX app. |
I would be great to have Quarkus able to run JavaFX applications. |
Hello, https://github.com/CodeSimcoe/quarkus-fx-extension Read the readme file to see how to use it in your application. |
Very cool. Will give it a try! |
Have you managed to give it a try ? |
completely fell through the cracks - taking a look now! |
I took a look:
|
Hello !
|
I tried the extension and it works well. I'm working on a chatbot using langChain4j and coded a simple gui for browsing the internal data. I can use DI as expected to get hold of all chatbot-related objects. There's two general things I miss:
|
BTW, I also tried it with jbang, here's a self-contained jbang class that worked for me:
|
P.S. It would be super cool to have an FXML string template processor that simplified loading embedded FXML snippets like the one above. |
I'll think/work on that when I get the opportunity to. Thanks ! Clement |
In branch https://github.com/CodeSimcoe/quarkus-fx-extension/tree/fx_startup, the application is automatically started (no more need to redefine the Quarkus main method and call the JavaFx Application::launch. |
If You are interested @CodeSimcoe - I Think it would be worth we create a quarkiverse repo to iterate on it. Is Quarkus-fx the best name ? /cc @gastaldi |
Let's do this @maxandersen |
I'd prefer Thoughts? |
All sound good to me |
taking a look at https://github.com/mhrimaz/AwesomeJavaFX I'll say its majority FX so io.quarkiverse.quarkus-fx works - and yeah it will use openjfx:javafx-* dependencies |
Repository https://github.com/quarkiverse/quarkus-fx created, welcome aboard @CodeSimcoe! Here are the next steps: https://hub.quarkiverse.io/checklist/#after-the-repository-is-created |
As a start, I've pushed code from my repo, with package update. |
I've added a "auto-launch" build time property, leveraging the need for a CDIApplication class. Please check https://github.com/quarkiverse/quarkus-fx Regards, |
Is a property really needed ? Wouldn't a @quarkusmain be sufficient similar how done for command mode/picocli? |
Can you give me some more details on what you could expect ? |
@maxandersen Thanks for the tip. |
Excellent :) |
|
@CodeSimcoe good - lets open issues on the quarkus-fx repo for future updates. |
Describe the extension
As discussed on Quarkus Insights with command mode we now can work with swing/javafx but we should have an extension to enable CDI injection in the UI eventqueues.
This one is for JavaFX and in this world Gluon Ignite seem to be the popular option.
Interested in this extension, please +1 via the emoji/reaction feature of GitHub (top right).
The text was updated successfully, but these errors were encountered: