Mega Code Archive

 
Categories / Java Tutorial / SWT
 

Add focus inout event to Text

import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Canvas; 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 FocusEventInOut {   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.FocusIn, new Listener() {       public void handleEvent(Event e) {         System.out.println("focus in");       }     });     t2.addListener(SWT.FocusOut, new Listener() {       public void handleEvent(Event e) {        System.out.println("focus out");       }     });          shell.setSize(200, 200);     shell.open();     while (!shell.isDisposed()) {       if (!display.readAndDispatch())         display.sleep();     }     display.dispose();   } }