Reputation: 809
I have developed plugin for Intellij Idea that contains code editor. And I want to use Intellij idea internal editor ui implementation, but I don't know how to add it to my window. Here is XML:
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="Playground" anchor="right" factoryClass="PlaygroundEditor" secondary="true"/>
</extensions>
Code:
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());
}
Result:
It doesn't works, I can't type here. Can you help me with it, maybe you have experience with intellij idea api, because current api so poor described.
Upvotes: 2
Views: 271
Reputation: 86
Try this:
Editor editor = EditorFactory.getInstance().createEditor(document);
JComponent editorComponent = editor.getComponent();
Upvotes: 2