Question

As a result of a custom Intellij action plugin developer can popup a dialog window with a custom UI. I am developing UI using JavaFX embedded into Swing panel.

JavaFX wise everything works fine. The problem is plugin class loader. It can't find any JavaFX class despite the fact that the IDEA version is 12.1.3 and JDK is 1.7.0_21. If I add jfxrt.jar as a compile dependency then everything works fine but it doesn't sound right to bring a standard jar together with a plugin.

Question: What is the correct way of adding JavaFX as the dependency of a plugin?

Was it helpful?

Solution

Three years and four IntelliJ versions (v16) later i will give everybody a hint how to use JavaFx in plugin development.

As an example, the following code demonstrates how to create a ToolWindow with JavaFx components:

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;


public class TestToolWindowFactory
implements ToolWindowFactory
{
    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow)
    {
        final JFXPanel fxPanel = new JFXPanel();
        JComponent component = toolWindow.getComponent();

        Platform.setImplicitExit(false);
        Platform.runLater(() -> {
            Group root  =  new Group();
            Scene scene  =  new  Scene(root, Color.ALICEBLUE);
            Text text  =  new Text();

            text.setX(40);
            text.setY(100);
            text.setFont(new Font(25));
            text.setText("Welcome JavaFX!");

            root.getChildren().add(text);

            fxPanel.setScene(scene);
        });

        component.getParent().add(fxPanel);
    }
}

Note: Because of JDK-8090517, it is important to invoke:

Platform.setImplicitExit(false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top