List of usage examples for org.eclipse.swt.widgets Display readAndDispatch
public boolean readAndDispatch()
true
if there is potentially more work to do, or false
if the caller can sleep until another event is placed on the event queue. From source file:org.eclipse.swt.snippets.Snippet29.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 29"); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar);/*from ww w. j a v a2s. c om*/ MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); fileItem.setText("&File"); Menu submenu = new Menu(shell, SWT.DROP_DOWN); fileItem.setMenu(submenu); MenuItem item = new MenuItem(submenu, SWT.PUSH); item.addListener(SWT.Selection, e -> System.out.println("Select All")); item.setText("Select &All\tCtrl+A"); item.setAccelerator(SWT.MOD1 + 'A'); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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"); }/*from w w w. j a va 2s . c o m*/ }); text.setMenu(menu); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cb.dispose(); 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);//from ww w . j ava2 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: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 w w . ja va2s . c om*/ 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: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 w ww . ja v a 2s .com*/ 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: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"); }/* w w w .ja va 2 s. 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: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 ww w . j a v a2s . c o m*/ 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: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); }/*from w w w .j a va 2s.co 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: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 a va 2 s. c o m } 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 .jav a 2 s.c o m 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(); }