简体   繁体   中英

Get XY position from caret position in JTextArea

I'm trying to make an editor which have ability show pop up (JPopupMenu) each time users type any letter. Maybe, to imagine how my editor works its like any compiler, such as NetBeans when we type dot, the function appear.

I have learned JPopupMenu from here . JPopupMenu needs XY position. My idea is to get XY position from JTextArea's caret position. My question is: Is there possible to get XY position from caret position (text cursor) in JTextArea or other JTextComponent? Or maybe is there any solution better to this case?

Thx before. Sorry, not good in english. :D

Rectangle rectangle = textArea.modelToView( textArea.getCaretPostion() );

所以你可能会使用Rectangle中的xy + height来定位弹出窗口。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM