我为Intellij Idea开发了包含代码编辑器的插件。而且我想使用Intellij想法内部编辑器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描述得很差。
答案 0 :(得分:2)
试试这个:
Editor editor = EditorFactory.getInstance().createEditor(document);
JComponent editorComponent = editor.getComponent();