开发者

SWT: Position a dialog based upon the position of the caret in a StyledText control

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜