Draw shapes in Editor
I have an instance of
com.intellij.openapi.fileEditor;
and I'm looking to draw shapes in it, to make "comment boxes" and help with documentation
but
newEditor.getComponent().getGraphics()
returns null, even in a SwingUtilities.invokeLater
Is there a better way of drawing shapes in an Editor? And if not, how can I get the editor's Graphics object.
Thanks.
Please sign in to leave a comment.
In Swing, graphics object is passed as a parameter to 'paintComponent' method. You can read the source code or debug the invocation of 'paintComponent' in EditorComponentImpl class to see the details of implementation of editor painting code. The only possible way to extend existing functionality currently is to add a RangeHighlighter to editor markup model which provides a CustomHighlightingRenderer.
See the following methods:
Beware that custom renderer painting is invoked after background is painted and before the text is painted. Adding such a renderer will not change the layout of text on the page, so what you can achieve with it is limited.