从JTextArea中的插入位置获取XY位置 [英] Get XY position from caret position in JTextArea

查看:139
本文介绍了从JTextArea中的插入位置获取XY位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次用户键入任何字母时,我都会尝试制作一个能够弹出能力的编辑器(JPopupMenu)。也许,想象一下我的编辑器如何像任何编译器一样工作,例如我们输入点时的NetBeans,函数出现。

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.

我从这里。 JPopupMenu需要XY位置。我的想法是从JTextArea的插入位置获得XY位置。我的问题是:是否有可能从JTExtArea或其他JTextComponent中的插入位置(文本光标)获取XY位置?或者也许这种情况有更好的解决方案吗?

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。对不起,英文不好。 :D

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

推荐答案

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

所以你可能会使用 x 和<来自矩形的code> y + height 来定位弹出窗口。

So you would probably use x and y + height from the Rectangle to position the popup.

这篇关于从JTextArea中的插入位置获取XY位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆