Combo default selection event (Return/Enter key) : Combo Event « SWT « Java Tutorial






Combo default selection event (Return/Enter key)
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Combo;
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 ComboDefaultSelection {

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());
    Combo combo = new Combo(shell, SWT.NONE);
    combo.setItems(new String[] { "A-1", "B-1", "C-1" });
    Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text.setText("some text");
    combo.addListener(SWT.DefaultSelection, new Listener() {
      public void handleEvent(Event e) {
        System.out.println(e.widget + " - Default Selection");
      }
    });
    text.addListener(SWT.DefaultSelection, new Listener() {
      public void handleEvent(Event e) {
        System.out.println(e.widget + " - Default Selection");
      }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}








17.12.Combo Event
17.12.1.Add selection listener to ComboAdd selection listener to Combo
17.12.2.Combo default selection event (Return/Enter key)Combo default selection event (Return/Enter key)
17.12.3.To track the user's selection (DefaultSelection)To track the user's selection (DefaultSelection)
17.12.4.Add TraverseListener to ComboAdd TraverseListener to Combo
17.12.5.Disable Tab key to transfer focus for ComboDisable Tab key to transfer focus for Combo