【发布时间】:2016-06-24 10:24:06
【问题描述】:
我尝试在多行文本字段中获取行号和“列”。问题是,如果我使用 getSelection() 并向下移动光标,我会得到 {0:0}、{5,5}、{10,10}。但我期望的是 {0,0}(第一行,第一列),{0,1}(第二行,第一列)和 {0,2}(第三行,第一列):
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout());
Text textBox = new Text(container, SWT.BORDER | SWT.H_SCROLL | SWT.MULTI | SWT.V_SCROLL);
textBox.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true));
textBox.setText("one\ntwo\nthree");
textBox.setSelection(0);
textBox.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
System.out.println(textBox.getSelection());
}
});
return container;
}
【问题讨论】: