【问题标题】:How to set Cursor position in SWT Text如何在 SWT 文本中设置光标位置
【发布时间】:2012-12-26 10:38:20
【问题描述】:

我试图在附加字符串后将 SWT Text 的光标位置设置到末尾。我知道更改 SWT StyledText 的光标位置,但不确定 SWT Text。如果您遇到此挑战并找到解决方案,请分享。

【问题讨论】:

  • 请使用尽可能多的标签来描述您的问题,而不仅仅是swt

标签: java text swt


【解决方案1】:

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

这会将光标设置到末尾。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 2011-03-14
    • 2023-03-15
    • 2015-11-23
    相关资源
    最近更新 更多