2017-03-05 89 views
2

我開發了包含代碼編輯器的Intellij Idea的插件。我想使用Intellij的想法內部編輯器UI實現,但我不知道如何將它添加到我的窗口。 這裏是XML:如何在我自己的插件中使用IntelliJ IDEA編輯器?

<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()); 
} 

結果:

enter image description here

它不工作,我不能在這裏輸入。你能幫助我嗎,也許你有intellij idea API的經驗,因爲目前的api很差描述。

回答

2

試試這個:

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

感謝它的作品)) – Silvestr

相關問題