使用JavaFX开发Intellij IDEA插件UI

Myk*_*yev 11 intellij-idea intellij-plugin javafx-2

由于自定义Intellij动作插件开发人员可以弹出一个带有自定义UI的对话窗口.我正在使用嵌入Swing面板的JavaFX开发UI.

JavaFX明智的一切正常.问题是插件类加载器.尽管IDEA版本为12.1.3且JDK为1.7.0_21,但它找不到任何JavaFX类.如果我将jfxrt.jar添加为编译依赖项,那么一切正常,但将标准jar与插件结合起来听起来不对.

问题:添加JavaFX作为插件依赖项的正确方法是什么?

kKd*_*KdH 14

三年和四个IntelliJ版本(v16)稍后我会给大家一个提示如何在插件开发中使用JavaFx.

作为示例,以下代码演示了如何使用JavaFx组件创建ToolWindow:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

注意:由于JDK-8090517,调用以下内容非常重要:

Platform.setImplicitExit(false);
Run Code Online (Sandbox Code Playgroud)