tags:

views:

12

answers:

1

I have SWT application that is a set of Groups that contain various controls including a StlyedText widget. They are all laid out using the Form layout.

I want to show a dialog directly below the caret inside of the StyledText. However, I have to position the dialog relative to the parent shell.

My first idea is to get the position of the shell plus the position of the StyledText plus the offset of the caret. When I try to get the position of the StyledText, it says 0,0 (I assume because of my layout choice, the Form layout). I don't see a good way to get the position from the FormData either (it appears to be computed).

I am able to get the position of the mouse cursor, but I would like to have it be right under what the user is typing.

Anyone have any ideas?

+2  A: 

In order to get the actual postion, the function toDisplay() should be used. For example:

Point displayPoint = myText.toDisplay(sqlText.getLocation());

That gets me to the position of the Text. I then added the caret position in order to move my dialog window to the line of text that is being written:

Point caretLocation = myText.getCaret().getLocation();
Point calcPoint = new Point(displayPoint.x+caretLocation.x, displayPoint.y+caretLocation.y);

I then used that location to position my dialog window.

Nick