List of usage examples for org.eclipse.swt.widgets Display Display
public Display()
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 a va 2s . c o m*/ shell.setLayout(new FillLayout()); TableTree tableTree = new TableTree(shell, SWT.NONE); Table table = tableTree.getTable(); table.setHeaderVisible(true); table.setLinesVisible(false); for (int i = 0; i < 3; i++) { new TableColumn(table, SWT.LEFT).setText("Column " + (i + 1)); } for (int i = 0; i < 3; i++) { TableTreeItem parent = new TableTreeItem(tableTree, SWT.NONE); parent.setText(0, "Parent " + (i + 1)); parent.setText(1, "Data"); parent.setText(2, "More data"); for (int j = 0; j < 3; j++) { TableTreeItem child = new TableTreeItem(parent, SWT.NONE); child.setText(0, "Child " + (j + 1)); child.setText(1, "Some child data"); child.setText(2, "More child data"); } parent.setExpanded(true); } // Pack the columns TableColumn[] columns = table.getColumns(); for (int i = 0, n = columns.length; i < n; i++) { columns[i].pack(); } shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.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 ww . j av a2s. c o m shell.setLayout(new FillLayout()); // Create a canvas Canvas canvas = new Canvas(shell, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.setLineWidth(10); e.gc.drawLine(0, 0, 100, 100); } }); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MainClass.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Sliders"); shell.setSize(300, 200);/* www . ja va 2 s .c o m*/ final Label label = new Label(shell, SWT.NONE); label.setText("Move the slider"); label.setBounds(0, 20, 150, 15); final Slider slider = new Slider(shell, SWT.HORIZONTAL); slider.setBounds(0, 40, 200, 20); final Text text = new Text(shell, SWT.BORDER); text.setBounds(0, 100, 200, 25); slider.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { String outString = "Event: SWT.NONE"; switch (event.detail) { case SWT.ARROW_DOWN: outString = "Event: SWT.ARROW_DOWN"; break; case SWT.ARROW_UP: outString = "Event: SWT.ARROW_UP"; break; case SWT.DRAG: outString = "Event: SWT.DRAG"; break; case SWT.END: outString = "Event: SWT.END"; break; case SWT.HOME: outString = "Event: SWT.HOME"; break; case SWT.PAGE_DOWN: outString = "Event: SWT.PAGE_DOWN"; break; case SWT.PAGE_UP: outString = "Event: SWT.PAGE_UP"; break; } outString += " Position: " + slider.getSelection(); text.setText(outString); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SWTListExampleDemo.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("List Example"); shell.setSize(300, 200);/*from ww w.j a va2 s. co m*/ shell.setLayout(new FillLayout(SWT.VERTICAL)); final List list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); for (int loopIndex = 0; loopIndex < 100; loopIndex++) { list.add("Item " + loopIndex); } list.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { int[] selections = list.getSelectionIndices(); String outText = ""; for (int loopIndex = 0; loopIndex < selections.length; loopIndex++) outText += selections[loopIndex] + " "; System.out.println("You selected: " + outText); } public void widgetDefaultSelected(SelectionEvent event) { int[] selections = list.getSelectionIndices(); String outText = ""; for (int loopIndex = 0; loopIndex < selections.length; loopIndex++) outText += selections[loopIndex] + " "; System.out.println("You selected: " + outText); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:DrawExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Drawing Example"); Canvas canvas = new Canvas(shell, SWT.NONE); canvas.setSize(150, 150);/*from www . j a va 2 s . c o m*/ canvas.setLocation(20, 20); shell.open(); shell.setSize(200, 220); GC gc = new GC(canvas); gc.drawRectangle(10, 10, 40, 45); gc.drawOval(65, 10, 30, 35); gc.drawLine(130, 10, 90, 80); gc.drawPolygon(new int[] { 20, 70, 45, 90, 70, 70 }); gc.drawPolyline(new int[] { 10, 120, 70, 100, 100, 130, 130, 75 }); gc.dispose(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ImageEmpty.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, 300, 200); GC gc = new GC(image); gc.drawLine(10, 10, 200, 200); gc.dispose();// w w w. j a v a2 s . co m e.gc.drawImage(image, 10, 10); image.dispose(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:GroupImageAdding.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Group group = new Group(shell, SWT.NONE); group.setLayout(new FillLayout()); group.setText("a square"); Canvas canvas = new Canvas(group, SWT.NONE); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(new Image(display, "yourFile.gif"), 0, 0); }/* w w w.j a v a 2 s .c om*/ }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FontRegistry.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(); shell.setLayout(new GridLayout(1, false)); FontRegistry fontRegistry = new FontRegistry(display); fontRegistry.put("button-text", new FontData[] { new FontData("Arial", 9, SWT.BOLD) }); fontRegistry.put("code", new FontData[] { new FontData("Courier New", 10, SWT.NORMAL) }); Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.WRAP); text.setFont(fontRegistry.get("code")); text.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); text.setText(""); GridData gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2;/* w w w. j a v a 2 s . c o m*/ text.setLayoutData(gd); Button executeButton = new Button(shell, SWT.PUSH); executeButton.setText("Execute"); executeButton.setFont(fontRegistry.get("button-text")); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet120.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(200, 200);//from ww w. ja v a2 s. com Monitor primary = display.getPrimaryMonitor(); Rectangle bounds = primary.getBounds(); Rectangle rect = shell.getBounds(); int x = bounds.x + (bounds.width - rect.width) / 2; int y = bounds.y + (bounds.height - rect.height) / 2; shell.setLocation(x, y); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ModifyListenerUsing.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("Type somthing to modify."); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent arg0) { System.out.println("Text modified"); }/*from w w w . j av a 2 s. c o m*/ }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }