List of usage examples for org.eclipse.swt.widgets Display Display
public Display()
From source file:SyntaxColoring.java
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); final String PUNCTUATION = "(){}"; styledText.addExtendedModifyListener(new ExtendedModifyListener() { public void modifyText(ExtendedModifyEvent event) { int end = event.start + event.length - 1; if (event.start <= end) { String text = styledText.getText(event.start, end); java.util.List ranges = new java.util.ArrayList(); for (int i = 0, n = text.length(); i < n; i++) { if (PUNCTUATION.indexOf(text.charAt(i)) > -1) { ranges.add(new StyleRange(event.start + i, 1, display.getSystemColor(SWT.COLOR_BLUE), null, SWT.BOLD)); }/*from w w w . j a v a2 s . c om*/ } if (!ranges.isEmpty()) { styledText.replaceStyleRanges(event.start, event.length, (StyleRange[]) ranges.toArray(new StyleRange[0])); } } } }); styledText.setBounds(10, 10, 500, 100); 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 ww w. ja v a 2 s .com e.detail = SWT.TRAVERSE_NONE; } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ImageLoadingFromFile.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Canvas Example"); shell.setLayout(new FillLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Image image = new Image(display, "yourFile.gif"); e.gc.drawImage(image, 10, 10); image.dispose();//from ww w .j a v a 2 s .c o m } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:LabelExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(); shell.setLayout(new GridLayout(1, false)); // Create a label new Label(shell, SWT.NONE).setText("This is a plain label."); // Create a vertical separator new Label(shell, SWT.SEPARATOR); // Create a label with a border new Label(shell, SWT.BORDER).setText("This is a label with a border."); // Create a horizontal separator Label separator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create a label with an image Image image = new Image(display, "java2s.gif"); Label imageLabel = new Label(shell, SWT.NONE); imageLabel.setImage(image);/*w w w . ja v a 2s . c o m*/ shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell shell = new Shell(d); shell.setSize(250, 200);/*from w w w. j av a2s . c o m*/ shell.setLayout(new RowLayout()); 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); String[] OPTIONS = { "A", "B", "C" }; list.setItems(OPTIONS); String selected = list.open(shell.getBounds()); System.out.println(selected); } }); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:HelloWorld4.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new HelloWorld4().open(display); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep();// ww w . j av a2 s .c o m } display.dispose(); }
From source file:ImageDisable.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Canvas Example"); shell.setLayout(new FillLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Image image = new Image(display, "yourFile.gif"); Image disable = new Image(display, image, SWT.IMAGE_DISABLE); e.gc.drawImage(disable, 10, 10); e.gc.drawImage(image, 10, 50); image.dispose();/* ww w. j a v a 2s . c o m*/ disable.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:TreeClass.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Tree Example"); final Text text = new Text(shell, SWT.BORDER); text.setBounds(0, 270, 290, 25);/*from ww w .jav a 2s.c o m*/ final Tree tree = new Tree(shell, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); tree.setSize(290, 260); shell.setSize(300, 330); for (int loopIndex0 = 0; loopIndex0 < 10; loopIndex0++) { TreeItem treeItem0 = new TreeItem(tree, 0); treeItem0.setText("Level 0 Item " + loopIndex0); for (int loopIndex1 = 0; loopIndex1 < 10; loopIndex1++) { TreeItem treeItem1 = new TreeItem(treeItem0, 0); treeItem1.setText("Level 1 Item " + loopIndex1); for (int loopIndex2 = 0; loopIndex2 < 10; loopIndex2++) { TreeItem treeItem2 = new TreeItem(treeItem1, 0); treeItem2.setText("Level 2 Item " + loopIndex2); } } } tree.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.detail == SWT.CHECK) { text.setText(event.item + " was checked."); } else { text.setText(event.item + " was selected"); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CellBackground.java
public static void main(String[] args) { Display display = new Display(); Color red = display.getSystemColor(SWT.COLOR_RED); Color gray = display.getSystemColor(SWT.COLOR_GRAY); Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER); table.setBackground(gray);//from ww w .j a v a2 s . c o m TableColumn column1 = new TableColumn(table, SWT.NONE); TableColumn column2 = new TableColumn(table, SWT.NONE); TableColumn column3 = new TableColumn(table, SWT.NONE); TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "normal", "blue background", "red background" }); item.setBackground(1, blue); item.setBackground(2, red); column1.pack(); column2.pack(); column3.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TreeNodeCollapseListener.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.ja va 2s .c om } } tree.addListener(SWT.Collapse, new Listener() { public void handleEvent(Event e) { System.out.println("Collapse={" + e.item + "}"); } }); tree.getItems()[0].setExpanded(true); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }