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

8

我正在尝试在追加字符串后将SWT Text的光标位置设置为末尾。我知道如何更改SWT StyledText的光标位置,但不确定SWT Text。如果您遇到这个问题并找到解决方案,请分享。


请尽可能使用多个标签来描述您的问题,而不仅仅是“swt”。 - Baz
1个回答

20

看一下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();
}

这将把光标设置到末尾。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接