How to : absolute (x,y) of the caret ?

How can I get the exact (x,y) Point location of the caret?
(I need it to draw around the caret with awt)

I tried this,

CaretModel caret = editor.getCaretModel();
Point point = editor.logicalPositionToXY (caret.getLogicalPosition() );

but it doesn't work :
- horizontal offset (always)
- vertical offset (when you use the scrollbar)

Alain Ravet

0
3 comments
Avatar
Permanently deleted user

Alain, your code is quite right though
editor.visualPositionToXY(caret.getVisualPosition()) would be slightly
faster.

Just keep in mind point is returned in coordinate system of
editor.getContentComponent().

Am I miss something?

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Alain Ravet" <alain.ravet.list@wanadoo.be> wrote in message
news:ap9uhs$u8d$1@is.intellij.net...

How can I get the exact (x,y) Point location of the caret?
(I need it to draw around the caret with awt)

>

I tried this,

>

CaretModel caret = editor.getCaretModel();
Point point = editor.logicalPositionToXY

(caret.getLogicalPosition() );
>

but it doesn't work :
- horizontal offset (always)
- vertical offset (when you use the scrollbar)

>

Alain Ravet

>


0
Avatar
Permanently deleted user

Of course, absolute coordinates may be fetched via
SwingUtilities.convertPointToScreen.

--

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"


"Maxim Shafirov" <max@intellij.net> wrote in message
news:apav7t$lqq$1@is.intellij.net...

Alain, your code is quite right though
editor.visualPositionToXY(caret.getVisualPosition()) would be slightly
faster.

>

Just keep in mind point is returned in coordinate system of
editor.getContentComponent().

>

Am I miss something?

>

--

>

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"

>
>

"Alain Ravet" <alain.ravet.list@wanadoo.be> wrote in message
news:ap9uhs$u8d$1@is.intellij.net...

How can I get the exact (x,y) Point location of the caret?
(I need it to draw around the caret with awt)

>

I tried this,

>

CaretModel caret = editor.getCaretModel();
Point point = editor.logicalPositionToXY

(caret.getLogicalPosition() );
>

but it doesn't work :
- horizontal offset (always)
- vertical offset (when you use the scrollbar)

>

Alain Ravet

>

>
>


0
Avatar
Permanently deleted user

Maxim Shafirov wrote:

> Just keep in mind point is returned in coordinate
> system of editor.getContentComponent().


My mistake : I was using
Graphics graphics = editor.getComponent().getGraphics();

Not, it works fine with
Graphics graphics = editor.getContentComponent().getGraphics();

Thanks.

Alain

0

Please sign in to leave a comment.