Add Traverse event to Canvas : Canvas « SWT « Java Tutorial






Add Traverse event to Canvas
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 CanvasTranverseEvent {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    
    final Canvas c = new Canvas(shell, SWT.BORDER);
    c.setBounds(10, 50, 100, 32);
    c.addListener(SWT.Traverse, new Listener() {
      public void handleEvent(Event e) {
        switch (e.detail) {
        /* Do tab group traversal */
        case SWT.TRAVERSE_ESCAPE:
          System.out.println("SWT.TRAVERSE_ESCAPE");
          break;
        case SWT.TRAVERSE_RETURN:
        case SWT.TRAVERSE_TAB_NEXT:
          System.out.println("SWT.TRAVERSE_TAB_NEXT");
          break;
        case SWT.TRAVERSE_TAB_PREVIOUS:
        case SWT.TRAVERSE_PAGE_NEXT:
        case SWT.TRAVERSE_PAGE_PREVIOUS:
          e.doit = true;
          break;
        }
      }
    });

    Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t.setBounds(10, 85, 100, 32);

    c.setFocus();
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}








17.20.Canvas
17.20.1.Repaint CanvasRepaint Canvas
17.20.2.Canvas: scroll an image (flicker free, no double buffering)Canvas: scroll an image (flicker free, no double buffering)
17.20.3.Add Traverse event to CanvasAdd Traverse event to Canvas
17.20.4.Add Controls to CanvasAdd Controls to Canvas
17.20.5.Add KeyEvent to CanvasAdd KeyEvent to Canvas