问题
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
回答1:
Rectangle rectangle = textArea.modelToView( textArea.getCaretPostion() );
So you would probably use x
and y + height
from the Rectangle to position the popup.
来源:https://stackoverflow.com/questions/18864368/get-xy-position-from-caret-position-in-jtextarea