ControlTabTransversing.java Source code

Java tutorial

Introduction

Here is the source code for ControlTabTransversing.java

Source

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class ControlTabTransversing {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new RowLayout());

        Text text1 = new Text(shell, SWT.SINGLE | SWT.BORDER);
        text1.setText("Can't Traverse");
        text1.addTraverseListener(new TraverseListener() {
            public void keyTraversed(TraverseEvent e) {
                switch (e.detail) {
                case SWT.TRAVERSE_TAB_NEXT:
                case SWT.TRAVERSE_TAB_PREVIOUS: {
                    e.doit = false;
                }
                }
            }
        });
        Text text2 = new Text(shell, SWT.SINGLE | SWT.BORDER);
        text2.setText("Can Traverse");
        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}