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.

1 comment
Comment actions Permalink

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:

TextEditor.getEditor()
Editor.getMarkupModel()
MarkupModel.addRangeHighlighter(...)
RangeHighlighter.setCustomRenderer(...)

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.

1

Please sign in to leave a comment.