[英]Eclipse text editor get caret position
As one component of a project I have a table with a list of variables from the current class in scope of the eclipse text editor. 作为项目的一个组成部分,我有一张表,该表列出了Eclipse文本编辑器范围内当前类的变量。 I want to be able to double click a position in this table and have the contents printed to the screen for me using a JavaRobot.
我希望能够双击此表中的一个位置,并使用JavaRobot将内容打印到屏幕上。 Everything is set but of course when I click the table, the text editor caret position disappears as the foreground job is the table.
一切都设置好了,但是当我单击表格时,文本编辑器的插入符号位置消失了,因为前台作业是表格。 Is there a way to find out the caret position so then I know where it was and thus print the contents into the desired location?
有没有办法找出插入符号的位置,以便我知道它在哪里,然后将内容打印到所需位置?
I have seen it done with textPanes: 我已经用textPanes看到了:
int currentCaretPosition = textPane.getCaretPosition();
On the left is an example table when I click it the cursor/caret position disappears. 当我单击它时,左侧是示例表,光标/插入符号位置消失了。
Need to get the cursor position and save it so I can print to this location using JavaRobot when a user double clicks a column/row. 需要获取光标位置并保存它,以便当用户双击列/行时可以使用JavaRobot打印到该位置。
Thanks 谢谢
Thanks guys, using SWT is what I needed :) 谢谢大家,我需要使用SWT :)
Here is the code for future reference: 这是代码,供将来参考:
CurrentDisplay display = new CurrentDisplay();
Display previousDisplay =display.getDisplay();
Point caretPoisition = previousDisplay.getCursorLocation();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.