import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class StyledTextListenerVerify {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
styledText.setText("text");
// use a verify listener to keep the offsets up to date
styledText.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
System.out.println(e.start);
System.out.println(e.start);
System.out.println(e.text.length());
}
});
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}