import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TextKeyEventListener {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
t.setBounds(10, 85, 100, 32);
Text t2 = new Text(shell, SWT.SINGLE | SWT.BORDER);
t2.setBounds(10, 25, 100, 32);
t2.addListener(SWT.KeyDown, new Listener() {
public void handleEvent(Event e) {
System.out.println("KEY");
}
});
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|