List of usage examples for org.eclipse.swt.widgets Display sleep
public boolean sleep()
From source file:PopupMenuMenuEvent.java
public static void main(String[] args) { Display display = new Display(); final Clipboard cb = new Clipboard(display); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP); Menu menu = new Menu(shell, SWT.POP_UP); final MenuItem copyItem = new MenuItem(menu, SWT.PUSH); copyItem.setText("Copy"); menu.addMenuListener(new MenuAdapter() { public void menuShown(MenuEvent e) { System.out.println("Menu event"); }// w w w . j a v a 2 s . c om }); text.setMenu(menu); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cb.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet183.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 183"); Link link = new Link(shell, SWT.NONE); String text = "The SWT component is designed to provide <a>efficient</a>, <a>portable</a> <a href=\"native\">access to the user-interface facilities of the operating systems</a> on which it is implemented."; link.setText(text);//from w ww . j a v a 2s .c o m Rectangle clientArea = shell.getClientArea(); link.setBounds(clientArea.x, clientArea.y, 400, 400); link.addListener(SWT.Selection, event -> System.out.println("Selection: " + event.text)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet11.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 11"); Text text = new Text(shell, SWT.BORDER | SWT.V_SCROLL); Rectangle clientArea = shell.getClientArea(); text.setBounds(clientArea.x + 10, clientArea.y + 10, 100, 100); for (int i = 0; i < 16; i++) { text.append("Line " + i + "\n"); }//from w w w. j a v a 2s . c o m shell.open(); text.setSelection(30); System.out.println("selection=" + text.getSelection()); System.out.println("caret position=" + text.getCaretPosition()); System.out.println("caret location=" + text.getCaretLocation()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ComboRemoveAll.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", "E", "F" }; final Combo combo = new Combo(shell, SWT.DROP_DOWN); combo.setItems(ITEMS);/* w w w . jav a2 s . c o m*/ combo.remove("C"); 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:ComboRemoveMultipleItems.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", "E", "F" }; final Combo combo = new Combo(shell, SWT.DROP_DOWN); combo.setItems(ITEMS);//from ww w.j av a 2s. c o m combo.remove(2, 4); 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:ToolBarWrapResize.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); final ToolBar toolBar = new ToolBar(shell, SWT.WRAP); for (int i = 0; i < 12; i++) { ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setText("Item " + i); }//w w w . j av a 2 s . c o m shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = shell.getClientArea(); Point size = toolBar.computeSize(rect.width, SWT.DEFAULT); toolBar.setSize(size); } }); toolBar.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:StyleRangeStyledTextSet.java
License:asdf
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); styledText.setText("asdfasdfasdfasdf12345678910234567890"); // Use the empty constructor and set the fields StyleRange sr1 = new StyleRange(); sr1.start = 7;//from www. ja v a 2 s .com sr1.length = 14; sr1.foreground = display.getSystemColor(SWT.COLOR_GREEN); sr1.background = display.getSystemColor(SWT.COLOR_WHITE); sr1.fontStyle = SWT.BOLD; styledText.setStyleRange(sr1); styledText.setBounds(10, 10, 500, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display d = new Display(); Shell s = new Shell(d); s.setSize(250, 250);//from w w w . ja v a 2 s . c o m s.setText("A Slider Example"); final Slider slide = new Slider(s, SWT.HORIZONTAL); slide.setBounds(15, 50, 125, 15); slide.setMinimum(0); slide.setMaximum(100); slide.setIncrement(1); final Text t = new Text(s, SWT.BORDER); t.setBounds(115, 25, 25, 25); t.setText("0"); slide.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { t.setText(new Integer(slide.getSelection()).toString()); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet76.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 76"); final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER); Rectangle clientArea = shell.getClientArea(); tabFolder.setLocation(clientArea.x, clientArea.y); for (int i = 0; i < 6; i++) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("TabItem " + i); Button button = new Button(tabFolder, SWT.PUSH); button.setText("Page " + i); item.setControl(button);/*from w w w . j ava 2 s .c om*/ } tabFolder.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet155.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 155"); shell.setLayout(new FillLayout()); Composite composite = new Composite(shell, SWT.EMBEDDED); /* Draw an X using AWT */ Frame frame = SWT_AWT.new_Frame(composite); Canvas canvas = new Canvas() { @Override//from w w w .j av a2 s .com public void paint(Graphics g) { Dimension d = getSize(); g.drawLine(0, 0, d.width, d.height); g.drawLine(d.width, 0, 0, d.height); } }; frame.add(canvas); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }