How to use a layered pane in a tool window?
Answered
I'm trying to display the editor for a Java file in a tool window, and cover up parts of the editor to limit what the user sees. I can get the editor to display by adding it to the ToolWindow component, but I'm having trouble getting the editor to display when adding it to the layered pane associated with the component.
Below is the code I have so far, and it doesn't display anything in the tool window. But if the line
// toolWindow.getComponent().add(editor.getComponent());
is uncommented, and the following line commented out, then it will correctly display the editor in the tool window.
What could be the problem?
public class EditorNodeTest implements ToolWindowFactory {
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
// Add the editor component to the tool window.
ApplicationManager.getApplication().invokeLater(() -> {
Document currentDocument = FileEditorManager.getInstance(project).getSelectedTextEditor().getDocument();
Editor editor = EditorFactory.getInstance().createEditor(currentDocument, project);
// toolWindow.getComponent().add(editor.getComponent());
toolWindow.getComponent().getRootPane().getLayeredPane().add(editor.getComponent());
});
}
}
Please sign in to leave a comment.
Is the size of the LayeredPane set properly? You may check the rendered components with the UI Inspector.