【问题标题】:How can I use IntelliJ IDEA editor in my own plugin?如何在我自己的插件中使用 IntelliJ IDEA 编辑器?
【发布时间】:2017-03-05 19:32:58
【问题描述】:

我为 Intellij Idea 开发了包含代码编辑器的插件。而且我想使用 Intellij idea 内部编辑器 ui 实现,但我不知道如何将它添加到我的窗口中。 这是 XML:

<extensions defaultExtensionNs="com.intellij">
    <toolWindow id="Playground" anchor="right" factoryClass="PlaygroundEditor" secondary="true"/>
</extensions>

代码:

public class PlaygroundEditor implements ToolWindowFactory {
private JPanel basePanel;

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    toolWindow.getContentManager().addContent(
            ContentFactory.SERVICE.getInstance().createContent(basePanel, "", false)
    );

    Document document = EditorFactory.getInstance().createDocument("public static void main(String... args) {\n}");
    document.setReadOnly(false);
    EditorFactory.getInstance().createEditor(document);
    EditorComponentImpl editorComponent = new EditorComponentImpl((EditorImpl) EditorFactory.getInstance().createEditor(document));

    basePanel.add(editorComponent, new GridConstraints());
}

结果:

它不起作用,我不能在这里输入。你能帮我解决一下吗,也许你有使用 intellij idea api 的经验,因为当前的 api 描述太差了。

【问题讨论】:

    标签: java swing intellij-idea plugins


    【解决方案1】:

    试试这个:

    Editor editor = EditorFactory.getInstance().createEditor(document);
    JComponent editorComponent = editor.getComponent();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 2015-03-25
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多