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

Dee*_*esh 7 java swt text

我试图Text在追加字符串后将SWT的光标位置设置为结尾.我知道改变SWT的光标位置StyledText,但不确定SWT Text.如果您有人遇到过这个挑战,并找到了解决方案,请分享它.

Baz*_*Baz 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();
}
Run Code Online (Sandbox Code Playgroud)

这会将光标设置为结尾.