/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class Snippet116 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Button b1 = new Button(shell, SWT.PUSH); b1.setText("Button 1"); b1.addSelectionListener(new SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { System.out.println("Button 1 selected"); } }); Button b2 = new Button(shell, SWT.PUSH); b2.setText("Button 2"); b2.addSelectionListener(new SelectionAdapter() { public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) { System.out.println("Button 2 selected"); } }); Text t = new Text(shell, SWT.SINGLE | SWT.BORDER); t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); t.setText("text"); t.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_RETURN) { System.out.println("Handle enter in text"); e.doit = true; e.detail = SWT.TRAVERSE_NONE; } } }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }