Does Intellij SDK work with JavaFX?

Hi,

My plugin works with swing and I want migrate it to JavaFX, but to no avail.
I tried to execute my plugin as JavaFX application and got:

Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
 at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
 at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
 at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
 at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
 at javafx.scene.Scene$5.invalidated(Scene.java:762)
 at javafx.beans.property.DoublePropertyBase.markInvalid(DoublePropertyBase.java:129)
 at javafx.beans.property.DoublePropertyBase.set(DoublePropertyBase.java:163)
 at javafx.scene.Scene.setWidth(Scene.java:744)
 at javafx.scene.Scene.init(Scene.java:1418)
 at javafx.scene.Scene.<init>(Scene.java:292)
 at javafx.scene.Scene.<init>(Scene.java:229)
 at mypackage.plugin.Main.start(Main.java:30)



My actionPerformed method implementation:

@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    javafx.application.Application.launch(Main.class);
}


:| Does Intellij SDK work with JavaFX? I'm using JDK 7.


UPDATE: After a some research I found the root of problem:


java.lang.ClassNotFoundException: javafx.scene.layout.AnchorPane
    at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:148)


Are someone solved this problem? I added jfxrt.jar to the list of dependencies with runtime scope, but anyway getting same error


SOLUTION
After a long unsuccessful attempts I finally done it!
Implementation of Application class:

@Override
public void start(Stage primaryStage) throws Exception{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("/fxml/main.fxml"));
    loader.setClassLoader(getClass().getClassLoader());
    Parent root = (Parent)loader.load();
    primaryStage.setScene(new Scene(root, 615, 244));
    primaryStage.setResizable(false);
    primaryStage.show();
}


Implementation of AnAction class:

private Stage stage;

@Override
public void actionPerformed(final AnActionEvent event) {
    PlatformImpl.startup(new Runnable() {
        @Override
        public void
run() {
            initialize();
        }
    });
}

private void initialize() {
    try {
        Main main = new Main();
        if (stage == null) {
            stage = new Stage();
        }
        main.start(stage);
    } catch (Exception e) {
        e.printStackTrace();
    }
}


And of course don't forget to add jfxrt.jar to the list of dependencies with runtime scope.

CONCLUSION
Because of some nasty bug with overlaying of one window to other and answer of Peter Schmitz, Intellij Plugin written in Java FX will not works correctly. For details see answers below.

4 comments
Comment actions Permalink

One problem of your approach is its missing portability.

It works because you included a copy of the JavaFX library from your runtime environment into your plugin.jar
See https://www.jetbrains.com/idea/help/dependencies-tab.html

Alternatively, use Build->Prepare for deployment  and take a look into your deployment ready jar-file. It includes a copy of
the jfxrt.jar from your machine and won't work in another OS.


As far as I understand it, the best solution should work with either the "Provided" setting for jfxrt.jar or no setting at all. Maybe throw in a check if the class is known to allow backwards compatibilty to JRE6 and alternative JREs


The setup described above was previously called 'ugly' (but working) approach in my thread (see https://devnet.jetbrains.com/message/5533581#5533581 ).
But thank you for providing the key aspects of it (the ClassLoader), since I haven't got around to upload an example to play around with

0
Comment actions Permalink

Hi,

Thank you for your reply.

In addition to above I want to add that Intellij has some nasty bug with overlaying of one window to other (e.g. in case of switching between a few Intellij windows). If you will use the Intellij plugin written in Java FX you will have the same problem: In case of re-opening your plugin, Intellij will overlay it. Thus, summarizing I can say with confidence that Intellij Plugin written in Java FX will not works correctly and I'm wondering that JetBrains team still did not care about it. :(

0
Comment actions Permalink

Probably a part of them not caring about it is the fact that plugins using JavaFX can still not be used on OSX, since on that platform JDK 1.6 is still the recommended JDK for running IntelliJ.

0
Comment actions Permalink

All my tests were conducted on Window 7 and Windows 8.1

0

Please sign in to leave a comment.