List of usage examples for org.eclipse.swt.widgets Display dispose
public void dispose()
From source file:org.eclipse.swt.examples.graphics.GraphicsExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new GraphicsExample().open(display); while (shell != null && !shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep();/*from w ww. j a va 2 s . com*/ } display.dispose(); }
From source file:ComboSetItems.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); String[] ITEMS = { "A", "B", "C", "D" }; final Combo combo = new Combo(shell, SWT.DROP_DOWN); combo.setItems(ITEMS);//from w ww.ja va 2 s . c om System.out.println(combo.getItemCount()); combo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { System.out.println(combo.getText()); } public void widgetDefaultSelected(SelectionEvent e) { System.out.println(combo.getText()); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet354.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 354"); shell.setLayout(new GridLayout(1, false)); Menu appMenuBar = display.getMenuBar(); if (appMenuBar == null) { appMenuBar = new Menu(shell, SWT.BAR); shell.setMenuBar(appMenuBar);// w ww. ja v a2s . c om } MenuItem file = new MenuItem(appMenuBar, SWT.CASCADE); file.setText("File"); Menu dropdown = new Menu(appMenuBar); file.setMenu(dropdown); MenuItem exit = new MenuItem(dropdown, SWT.PUSH); exit.setText("Exit"); exit.addSelectionListener(widgetSelectedAdapter(e -> display.dispose())); Listener keyDownFilter = event -> System.out.println("Key event!"); display.addFilter(SWT.KeyDown, keyDownFilter); display.addFilter(SWT.KeyUp, keyDownFilter); ArmListener armListener = e -> System.out.println(e); Menu systemMenu = display.getSystemMenu(); if (systemMenu != null) { systemMenu.addMenuListener(new MenuListener() { @Override public void menuHidden(MenuEvent e) { System.out.println("App menu closed"); } @Override public void menuShown(MenuEvent e) { System.out.println("App menu opened"); } }); MenuItem sysItem = getItem(systemMenu, SWT.ID_QUIT); sysItem.addArmListener(armListener); sysItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Quit selected"))); sysItem = getItem(systemMenu, SWT.ID_HIDE_OTHERS); sysItem.addArmListener(armListener); sysItem.addSelectionListener(widgetSelectedAdapter(e -> { System.out.println("Hide others selected -- and blocked!"); e.doit = false; })); sysItem = getItem(systemMenu, SWT.ID_HIDE); sysItem.addArmListener(armListener); sysItem.addSelectionListener(widgetSelectedAdapter(e -> { System.out.println("Hide selected -- and blocked!"); e.doit = false; })); sysItem = getItem(systemMenu, SWT.ID_PREFERENCES); sysItem.addArmListener(armListener); sysItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Preferences selected"))); sysItem = getItem(systemMenu, SWT.ID_ABOUT); sysItem.addArmListener(armListener); sysItem.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("About selected"))); int prefsIndex = systemMenu.indexOf(getItem(systemMenu, SWT.ID_PREFERENCES)); MenuItem newAppMenuItem = new MenuItem(systemMenu, SWT.CASCADE, prefsIndex + 1); newAppMenuItem.setText("SWT-added item"); newAppMenuItem.setAccelerator(SWT.MOD1 | 'i'); newAppMenuItem.addArmListener(armListener); newAppMenuItem.addSelectionListener( widgetSelectedAdapter(e -> System.out.println("SWT-added item selected"))); Menu subMenu = new Menu(systemMenu); for (int i = 0; i < 4; i++) { MenuItem subItem = new MenuItem(subMenu, SWT.PUSH); subItem.setText("Item " + i); } newAppMenuItem.setMenu(subMenu); } Button b = new Button(shell, SWT.PUSH); b.setText("Test"); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet57.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 57"); final ProgressBar bar = new ProgressBar(shell, SWT.SMOOTH); Rectangle clientArea = shell.getClientArea(); bar.setBounds(clientArea.x, clientArea.y, 200, 32); shell.open();//from ww w . j a v a2 s. co m display.timerExec(100, new Runnable() { int i = 0; @Override public void run() { if (bar.isDisposed()) return; bar.setSelection(i++); if (i <= bar.getMaximum()) display.timerExec(100, this); } }); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // Create a List with a vertical scroll bar List list = new List(shell, SWT.V_SCROLL); // Add a bunch of items to it for (int i = 0; i < 500; i++) { list.add("A list item"); }//from w ww .j a v a 2s . co m // Scroll to the bottom list.select(list.getItemCount() - 1); list.showSelection(); // Get the scroll bar ScrollBar sb = list.getVerticalBar(); // Add one more item that shows the selection value list.add("Selection: " + sb.getSelection()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ComboTransferFocus.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); text.setText("Press TAB"); Combo combo = new Combo(shell, SWT.NONE); combo.setItems(new String[] { "Press enter to select", "B-1", "C-1" }); combo.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_TAB_NEXT) { e.doit = false;//from w w w. jav a2 s . co m e.detail = SWT.TRAVERSE_NONE; } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet252.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 252"); shell.addListener(SWT.Paint, event -> { GC gc = event.gc;//from w w w.j ava2 s. c o m gc.setLineAttributes(new LineAttributes(10, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_SOLID, null, 0, 10)); gc.drawPolyline(new int[] { 50, 100, 50, 20, 60, 30, 50, 45 }); gc.setLineAttributes( new LineAttributes(1 / 2f, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_DOT, null, 0, 10)); gc.drawPolyline(new int[] { 100, 100, 100, 20, 110, 30, 100, 45 }); }); shell.setSize(150, 150); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollBarExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // Create a List with a vertical scroll bar List list = new List(shell, SWT.V_SCROLL); // Add a bunch of items to it for (int i = 0; i < 500; i++) { list.add("A list item"); }//from w w w . jav a2 s .c om // Scroll to the bottom list.select(list.getItemCount() - 1); list.showSelection(); // Get the scroll bar ScrollBar sb = list.getVerticalBar(); // Add one more item that shows the selection value list.add("Selection: " + sb.getSelection()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:LineCapsSetting.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { int x = 20, y = 20, w = 120, h = 60; GC gc = event.gc;/* www .ja va 2 s. c om*/ gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.setLineWidth(10); int[] caps = { SWT.CAP_FLAT, SWT.CAP_ROUND, SWT.CAP_SQUARE }; for (int i = 0; i < caps.length; i++) { gc.setLineCap(caps[i]); gc.drawLine(x, y, x + w, y); y += 20; } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet55.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 55"); Text text = new Text(shell, SWT.BORDER); text.setFont(new Font(display, "Courier", 13, SWT.NORMAL)); // Use a fixed size font Rectangle clientArea = shell.getClientArea(); text.setLocation(clientArea.x, clientArea.y); int columns = 10; GC gc = new GC(text); FontMetrics fm = gc.getFontMetrics(); int width = (int) (columns * fm.getAverageCharacterWidth()); int height = fm.getHeight(); gc.dispose();//from w w w .j ava 2s. c o m text.setSize(text.computeSize(width, height)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }