简体   繁体   English

从JTextArea中的插入位置获取XY位置

[英]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. 每次用户输入任何字母时,我都会尝试制作一个能够弹出能力的编辑器(JPopupMenu)。 Maybe, to imagine how my editor works its like any compiler, such as NetBeans when we type dot, the function appear. 也许,想象我的编辑器如何像任何编译器一样工作,例如当我们键入点时NetBeans,该函数出现。

I have learned JPopupMenu from here . 我从这里学到了JPopupMenu。 JPopupMenu needs XY position. JPopupMenu需要XY位置。 My idea is to get XY position from JTextArea's caret position. 我的想法是从JTextArea的插入位置获得XY位置。 My question is: Is there possible to get XY position from caret position (text cursor) in JTextArea or other JTextComponent? 我的问题是:是否有可能从JTExtArea或其他JTextComponent中的插入位置(文本光标)获取XY位置? Or maybe is there any solution better to this case? 或者也许这种情况有更好的解决方案吗?

Thx before. 先谢谢。 Sorry, not good in english. 对不起,英文不好。 :D :d

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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