List of usage examples for org.eclipse.swt.widgets Display Display
public Display()
From source file:StyledTextListenerVerify.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); styledText.setText("text"); // use a verify listener to keep the offsets up to date styledText.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent e) { System.out.println(e.start); System.out.println(e.start); System.out.println(e.text.length()); }/*from w w w . ja v a2 s. c om*/ }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FormLayoutControlOffsetAttachment.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Point size = button1.computeSize(SWT.DEFAULT, SWT.DEFAULT); int offset = size.x / 2; FormData formData = new FormData(); formData.left = new FormAttachment(50, -1 * offset); button1.setLayoutData(formData);/*w w w . j a v a 2 s . c om*/ shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:SystemFileIconLoad.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NONE); Image image = null;//from ww w.ja v a 2 s .com Program p = Program.findProgram(".txt"); ImageData data = p.getImageData(); image = new Image(display, data); label.setImage(image); p = Program.findProgram(".bmp"); data = p.getImageData(); image = new Image(display, data); label = new Label(shell, SWT.NONE); label.setImage(image); p = Program.findProgram(".doc"); data = p.getImageData(); image = new Image(display, data); label = new Label(shell, SWT.NONE); label.setImage(image); label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:TreeNodeSelectionListener.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); for (int i = 0; i < 4; i++) { TreeItem item0 = new TreeItem(tree, 0); item0.setText("Item " + i); for (int j = 0; j < 4; j++) { TreeItem item1 = new TreeItem(item0, 0); item1.setText("SubItem " + i + " " + j); for (int k = 0; k < 4; k++) { TreeItem item2 = new TreeItem(item1, 0); item2.setText("SubItem " + i + " " + j + " " + k); }//from w w w .j a v a 2 s.co m } } tree.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String string = ""; TreeItem[] selection = tree.getSelection(); for (int i = 0; i < selection.length; i++) string += selection[i] + " "; System.out.println("Selection={" + string + "}"); } }); tree.getItems()[0].setExpanded(true); shell.pack(); 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 . j a va 2 s. c o m s.setText("A FormLayout Example"); s.setLayout(new FormLayout()); final Label l1 = new Label(s, SWT.RIGHT); l1.setText("First Name"); FormData fd = new FormData(); fd.top = new FormAttachment(10, 10); fd.left = new FormAttachment(0, 10); fd.bottom = new FormAttachment(30, 0); fd.right = new FormAttachment(40, 0); l1.setLayoutData(fd); final Label l2 = new Label(s, SWT.RIGHT); l2.setText("Last Name"); fd = new FormData(); fd.top = new FormAttachment(l1, 5); fd.left = new FormAttachment(0, 10); fd.bottom = new FormAttachment(40, 0); fd.right = new FormAttachment(40, 0); l2.setLayoutData(fd); final Text t1 = new Text(s, SWT.BORDER | SWT.SINGLE); fd = new FormData(); fd.top = new FormAttachment(l1, 0, SWT.TOP); fd.left = new FormAttachment(l1, 10); t1.setLayoutData(fd); final Text t2 = new Text(s, SWT.BORDER | SWT.SINGLE); fd = new FormData(); fd.top = new FormAttachment(l2, 0, SWT.TOP); fd.left = new FormAttachment(l2, 10); t2.setLayoutData(fd); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:SashSlimDragger.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Sash One"); shell.setLayout(new FormLayout()); Sash sash = new Sash(shell, SWT.VERTICAL); FormData data = new FormData(); data.top = new FormAttachment(0, 0); // Attach to top data.bottom = new FormAttachment(100, 0); // Attach to bottom data.left = new FormAttachment(50, 0); // Attach halfway across sash.setLayoutData(data);/*from w ww. ja v a2 s . c o m*/ Text one = new Text(shell, SWT.BORDER); data = new FormData(); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(sash, 0); one.setLayoutData(data); Text two = new Text(shell, SWT.BORDER); data = new FormData(); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(sash, 0); data.right = new FormAttachment(100, 0); two.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FocusListenerUsing.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(3, true)); shell.setText("One Potato, Two Potato"); // Create the focus listener FocusListener listener = new FocusListener() { public void focusGained(FocusEvent event) { Button button = (Button) event.getSource(); button.setText("I'm It!"); }/* ww w. j a va 2s . c om*/ public void focusLost(FocusEvent event) { Button button = (Button) event.getSource(); button.setText("Pick Me!"); } }; // Create the buttons and add the listener to each one for (int i = 0; i < 6; i++) { Button button = new Button(shell, SWT.PUSH); button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); button.setText("Pick Me!"); button.addFocusListener(listener); } // Display the window shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ComboSortList.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" }; Arrays.sort(ITEMS);//from www. j av a 2 s. co m final Combo combo = new Combo(shell, SWT.DROP_DOWN); combo.setItems(ITEMS); combo.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { System.out.println("Selected index: " + combo.getSelectionIndex() + ", selected item: " + combo.getItem(combo.getSelectionIndex()) + ", text content in the text field: " + combo.getText()); } public void widgetDefaultSelected(SelectionEvent e) { System.out.println("Default selected index: " + combo.getSelectionIndex() + ", selected item: " + (combo.getSelectionIndex() == -1 ? "<null>" : combo.getItem(combo.getSelectionIndex())) + ", text content in the text field: " + combo.getText()); String text = combo.getText(); if (combo.indexOf(text) < 0) { // Not in the list yet. combo.add(text); // Re-sort String[] items = combo.getItems(); Arrays.sort(items); combo.setItems(items); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ToolbarClass.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(300, 200);/* w ww .ja v a 2s. c om*/ shell.setText("Toolbar Example"); ToolBar toolbar = new ToolBar(shell, SWT.NONE); toolbar.setBounds(0, 0, 200, 70); ToolItem toolItem1 = new ToolItem(toolbar, SWT.PUSH); toolItem1.setText("Save"); ToolItem toolItem2 = new ToolItem(toolbar, SWT.PUSH); toolItem2.setText("Save As"); ToolItem toolItem3 = new ToolItem(toolbar, SWT.PUSH); toolItem3.setText("Print"); ToolItem toolItem4 = new ToolItem(toolbar, SWT.PUSH); toolItem4.setText("Run"); ToolItem toolItem5 = new ToolItem(toolbar, SWT.PUSH); toolItem5.setText("Help"); final Text text = new Text(shell, SWT.BORDER); text.setBounds(55, 80, 200, 25); Listener toolbarListener = new Listener() { public void handleEvent(Event event) { ToolItem toolItem = (ToolItem) event.widget; String caption = toolItem.getText(); text.setText("You clicked " + caption); } }; toolItem1.addListener(SWT.Selection, toolbarListener); toolItem2.addListener(SWT.Selection, toolbarListener); toolItem3.addListener(SWT.Selection, toolbarListener); toolItem4.addListener(SWT.Selection, toolbarListener); toolItem5.addListener(SWT.Selection, toolbarListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeMultiSelection.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("TreeExample"); Tree tree = new Tree(shell, SWT.MULTI | SWT.BORDER); // Turn off drawing to avoid flicker tree.setRedraw(false);// ww w . j a v a2 s . co m for (int i = 0; i < 5; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Root Item " + i); for (int j = 0; j < 3; j++) { TreeItem child = new TreeItem(item, SWT.NONE); child.setText("Child Item " + i + " - " + j); for (int k = 0; k < 3; k++) { TreeItem grandChild = new TreeItem(child, SWT.NONE); grandChild.setText("Grandchild Item " + i + " - " + j + " - " + k); } } } tree.setRedraw(true); tree.setBounds(10, 10, 400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }