List of usage examples for org.eclipse.swt.widgets Display dispose
public void dispose()
From source file:org.eclipse.swt.snippets.Snippet112.java
public static void main(String[] args) { Display display = new Display(); final Image image = new Image(display, 20, 20); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);//from www. j a v a 2s . c o m gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); shell.setText("Snippet 112"); shell.setLayout(new FillLayout()); Group group = new Group(shell, SWT.NONE); group.setLayout(new FillLayout()); group.setText("a square"); Canvas canvas = new Canvas(group, SWT.NONE); canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:GridLayoutMargin.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 20;// ww w . j a va 2s .c om gridLayout.marginWidth = 30; shell.setLayout(gridLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); Button button3 = new Button(shell, SWT.PUSH); button3.setText("button #3"); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet317.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 317"); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;/*ww w . j a va 2 s . c o m*/ shell.setLayout(gridLayout); final Text location = new Text(shell, SWT.BORDER); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; location.setLayoutData(data); Button go = new Button(shell, SWT.PUSH); go.setText("Go"); final Browser browser; try { browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } data = new GridData(); data.horizontalAlignment = data.verticalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = data.grabExcessVerticalSpace = true; data.horizontalSpan = 2; browser.setLayoutData(data); browser.setUrl("eclipse.org"); browser.addLocationListener(new LocationAdapter() { @Override public void changed(LocationEvent event) { location.setText(event.location); } }); Listener navigateListener = event -> browser.setUrl(location.getText()); go.addListener(SWT.Selection, navigateListener); location.addListener(SWT.DefaultSelection, navigateListener); browser.addAuthenticationListener(event -> { try { URL url = new URL(event.location); if (url.getHost().equals(KNOWN_HOST)) { event.user = KNOWN_USER; event.password = KNOWN_PASSWORD; } else { /* do nothing, let default prompter run */ } } catch (MalformedURLException e) { /* should not happen, let default prompter run */ } }); shell.setBounds(10, 10, 500, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet127.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Button button1 = new Button(shell, SWT.PUSH); button1.setBounds(10, 10, 80, 30);/*from w w w. ja v a 2 s.c o m*/ button1.setText("no traverse"); button1.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { switch (e.detail) { case SWT.TRAVERSE_TAB_NEXT: case SWT.TRAVERSE_TAB_PREVIOUS: { e.doit = false; } } } }); Button button2 = new Button(shell, SWT.PUSH); button2.setBounds(100, 10, 80, 30); button2.setText("can traverse"); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet53.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); final Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setSize(200, 200);/* w ww .j a v a 2 s . co m*/ for (int i = 0; i < 128; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText("Item " + i); } Menu menu = new Menu(shell, SWT.POP_UP); table.setMenu(menu); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Delete Selection"); item.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { table.remove(table.getSelectionIndices()); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet276.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 276"); shell.setBounds(200, 200, 400, 400); Label label = new Label(shell, SWT.NONE); label.setText("click in shell to print display-relative coordinate"); Listener listener = event -> {//from ww w . j av a2 s .c o m Point point = new Point(event.x, event.y); System.out.println(display.map((Control) event.widget, null, point)); }; shell.addListener(SWT.MouseDown, listener); label.addListener(SWT.MouseDown, listener); Rectangle clientArea = shell.getClientArea(); label.setLocation(clientArea.x, clientArea.y); label.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeItemMousePostion.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 12; i++) { TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText("Item " + i); }/*from www . j a va2s.c o m*/ tree.addListener(SWT.MouseDown, new Listener() { public void handleEvent(Event event) { Point point = new Point(event.x, event.y); TreeItem item = tree.getItem(point); if (item != null) { System.out.println("Mouse down: " + item); } } }); tree.setSize(200, 200); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:PopupListUsing.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("PopupList Test"); shell.setLayout(new RowLayout()); // Create a button to launch the list Button button = new Button(shell, SWT.PUSH); button.setText("Push Me"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { PopupList list = new PopupList(shell); list.setItems(new String[] { "A", "B", "C" }); String selected = list.open(shell.getBounds()); System.out.println(selected); }//w w w . ja v a 2s . c o m }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ListDefaultSelectionListener.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); final List list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); for (int i = 0; i < 128; i++) { list.add("Item " + i); }/*from w ww . j a va2 s . c o m*/ list.setBounds(0, 0, 100, 100); list.addListener(SWT.DefaultSelection, new Listener() { public void handleEvent(Event e) { String string = ""; int[] selection = list.getSelectionIndices(); for (int i = 0; i < selection.length; i++) string += selection[i] + " "; System.out.println("DefaultSelection={" + string + "}"); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }