1 /* 2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.jemmy.swt; 24 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.ModifyEvent; 27 import org.eclipse.swt.events.ModifyListener; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.events.SelectionListener; 30 import org.eclipse.swt.layout.RowLayout; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Combo; 33 import org.eclipse.swt.widgets.Display; 34 import org.eclipse.swt.widgets.List; 35 import org.eclipse.swt.widgets.Shell; 36 import org.eclipse.swt.widgets.Text; 37 38 /** 39 * 40 * @author shura 41 */ 42 public class Sample { 43 44 public static void main(String[] args) { 45 //Creates a new display object for the example to go into 46 Display display = Display.getDefault(); 47 //Creates a new shell object 48 final Shell shell = new Shell(display); 49 //Sets the layout for the shell 50 shell.setLayout(new RowLayout()); 51 final Text lbl = new Text(shell, SWT.DEFAULT); 52 lbl.setText("click the button, please."); 53 lbl.setBounds(0, 0, 100, 30); 54 lbl.setEditable(true); 55 Button btn = new Button(shell, SWT.DEFAULT); 56 btn.setText("Click me!"); 57 btn.addSelectionListener(new SelectionListener() { 58 59 public void widgetSelected(SelectionEvent arg0) { 60 lbl.setText("Now type some new text"); 61 System.out.println(shell.getLocation()); 62 } 63 64 public void widgetDefaultSelected(SelectionEvent arg0) { 65 //System.out.println(arg0); 66 } 67 }); 68 Combo combo = new Combo(shell, SWT.DEFAULT); 69 combo.add("one"); 70 combo.add("two"); 71 combo.add("three"); 72 combo.add("four"); 73 combo.select(0); 74 List list = new List(shell, SWT.DEFAULT); 75 list.add("one"); 76 list.add("two"); 77 list.add("three"); 78 list.add("four"); 79 list.select(0); 80 //Creates the control example - see import statement for location. 81 shell.setText("Control Example"); 82 shell.setBounds(100, 100, 300, 200); 83 shell.open(); 84 while (!shell.isDisposed()) { 85 if (!display.readAndDispatch()) { 86 display.sleep(); 87 } 88 } 89 } 90 }