List of usage examples for org.eclipse.swt.widgets Display Display
public Display()
From source file:DrawPolygonSWT.java
public static void main(String[] args) { Display display = new Display(); 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) { Canvas canvas = (Canvas) e.widget; int x = canvas.getBounds().width; int y = canvas.getBounds().height; e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLACK)); // Create the points for drawing a triangle in the upper left int[] upper_left = { 0, 0, 200, 0, 0, 200 }; // Create the points for drawing a triangle in the lower right int[] lower_right = { x, y, x, y - 200, x - 200, y }; // Draw the triangles e.gc.fillPolygon(upper_left); e.gc.fillPolygon(lower_right); }/*from ww w.j av a 2s. c om*/ }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ScrollCompisiteHoriVertical.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SashForm Test"); shell.setLayout(new FillLayout()); // Create the ScrolledComposite to scroll horizontally and vertically ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); child.setSize(400, 400);//w w w. ja v a 2 s.co m sc.setContent(child); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:EventSelection.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new FillLayout()); Button button = new Button(shell, SWT.RIGHT); button.setText("text on the button"); button.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { System.out.println("selected"); }//from w w w . j ava 2s . co m public void widgetDefaultSelected(SelectionEvent arg0) { } }); shell.open(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue 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, 200);//from ww w . j a v a2s.c om s.setText("A KeyListener Example"); s.setLayout(new RowLayout()); final Combo c = new Combo(s, SWT.DROP_DOWN | SWT.BORDER); c.add("A"); c.add("B"); c.add("C"); c.add("D"); c.addKeyListener(new KeyListener() { String selectedItem = ""; public void keyPressed(KeyEvent e) { if (c.getText().length() > 0) { return; } String key = Character.toString(e.character); String[] items = c.getItems(); for (int i = 0; i < items.length; i++) { if (items[i].toLowerCase().startsWith(key.toLowerCase())) { c.select(i); selectedItem = items[i]; return; } } } public void keyReleased(KeyEvent e) { if (selectedItem.length() > 0) c.setText(selectedItem); selectedItem = ""; } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:GridLayoutIndentation.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;/* w w w. j ava2 s . com*/ gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); // Default alignment List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END)); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END); gridData.horizontalIndent = 50; button2.setLayoutData(gridData); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:BrowserProgress.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Browser browser = new Browser(shell, SWT.NONE); browser.setBounds(5, 5, 600, 600);/*www .ja va2s . c om*/ final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE); progressBar.setBounds(5, 650, 600, 20); browser.addProgressListener(new ProgressListener() { public void changed(ProgressEvent event) { if (event.total == 0) return; int ratio = event.current * 100 / event.total; progressBar.setSelection(ratio); } public void completed(ProgressEvent event) { progressBar.setSelection(0); } }); browser.setUrl("http://java2s.com"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); final Shell shell = new Shell(display); final List list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); list.setBounds(40, 20, 220, 100);/*from ww w .j a v a 2s . co m*/ for (int loopIndex = 0; loopIndex < 9; loopIndex++) { list.add("Item Number " + loopIndex); } final Text text = new Text(shell, SWT.BORDER); text.setBounds(60, 130, 160, 25); list.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { int[] selectedItems = list.getSelectionIndices(); String outString = ""; for (int loopIndex = 0; loopIndex < selectedItems.length; loopIndex++) outString += selectedItems[loopIndex] + " "; text.setText("Selected Items: " + outString); } public void widgetDefaultSelected(SelectionEvent event) { int[] selectedItems = list.getSelectionIndices(); String outString = ""; for (int loopIndex = 0; loopIndex < selectedItems.length; loopIndex++) outString += selectedItems[loopIndex] + " "; System.out.println("Selected Items: " + outString); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:OpenWindowListenerUsing.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); Browser browser = new Browser(shell, SWT.NONE); browser.setBounds(5, 5, 600, 600);/* w w w . j a v a 2s .c om*/ browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { Shell shell = new Shell(display); shell.setText("New Window"); shell.setLayout(new FillLayout()); Browser browser = new Browser(shell, SWT.NONE); event.browser = browser; } }); browser.setUrl("http://java2s.com"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CreateSingleSelectionListAddItems.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // Create a single-selection list List single = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL); // Add the items, one by one for (int i = 0, n = ITEMS.length; i < n; i++) { single.add(ITEMS[i]);//from w w w.j a va 2 s . c om } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:GridLayoutVerticalAlignment.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;//w w w. jav a 2 s . co m gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); // Default alignment List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); list.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); button2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END)); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); button3.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }