I have a JTextPane and want to know if there is a way to get the (x,y) pixel position of the current cursor. I don't want the caret position that's from getCaretPosition(), but the pixel co-ordinates of where the cursor currently is.

I'm using a variable width font in the pane, so simply multiplying the cursor position by some fixed width won't work.

I need this because I want a JPopUpMenu to appear directly below where the cursor is, and the JPopUpMenu show() method only takes (x,y) pixel coordinates.

All help is appreciated. Thanks.

This may work for you. Assuming textPane on a panel

SwingUtilities.convertPoint(textPane, textPane.getCaret().getMagicCaretPosition(), panel)