0

I'm trying to display a tooltip below caret position, the same way Eclipse prompts "Enter new name, press Enter to refactor" when renaming local variable. I assume that I can't use ToolTip as they are binded to mouse and not caret, so I'd have to adapt ToolTipManager.showTipWindow() code for my purposes. Here, the only problem is calculating caret position in pixels. I attempted:

Caret c = editor.getCaret();
Point location = c.getMagicCaretPosition();

where subsequent use of location causes NPE. I guess this happens when caret is not visible, so the method is unreliable. Is there a way to convert character offset in the TextArea, to the Point location?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Tegiri Nenashi
  • 3,066
  • 2
  • 19
  • 20

1 Answers1

2

Use modelToView() method of JTextArea.

StanislavL
  • 56,971
  • 9
  • 68
  • 98