如何在SWT文本中设置光标位置

时间:2012-12-26 10:38:20

标签: java text swt

我试图在附加字符串后将SWT Text的光标位置设置为结尾。我知道更改SWT StyledText的光标位置,但不确定SWT Text。如果你有人遇到过这个挑战,并且发现解决方案可以分享它。

1 个答案:

答案 0 :(得分:19)

查看Text#setSelection(int)

public static void main(String[] args)
{
    Display d = new Display();
    final Shell shell = new Shell(d);
    shell.setLayout(new GridLayout(1, false));

    Text text = new Text(shell, SWT.BORDER);

    text.setText("Some random text here...");

    text.setSelection(text.getText().length());


    shell.pack();
    shell.open();
    while (!shell.isDisposed())
        while (!d.readAndDispatch())
            d.sleep();
}

这会将光标设置为结束。

相关问题