Get Editor position/index on screen


I'm working on a plugin where a split view editor will "follow" the file in another editor: specifically I want to show the corresponding C header/source for whatever is in the "first" split editor.  "First" meaning whatever's at the leftmost, or top-left most corner.

Is there a way to determine positional layout of an Editor?  XY relative to window or some such would work, too.


com.intellij.openapi.editor.Editor#getContentComponent -> java.awt.Component#getLocationOnScreen should work


Hi Yann, thanks for the tip.

I'm using getLocationOnScreen() inside EditorFactoryListener.editorCreated() and receiving the exception 'java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location"

It seems that when EditorFactoryListener.editorCreated() is called the new Editor's Component hasn't yet been displayed.  Is there a better place to get its location (when or shortly after it is created?).  Or can I force it to display or calculate its position before editorCreated() has finished?


You can use com.intellij.util.ui.update.UiNotifyConnector#showNotify to trigger when the editor component is actually shown


That worked great, thank you.


Please sign in to leave a comment.