문제

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() );

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top