Question

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

Was it helpful?

Solution

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top