List of usage examples for org.eclipse.swt.widgets Display Display
public Display()
From source file:FormLayoutAnotherControl.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"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button2"); FormData formData = new FormData(); formData.left = new FormAttachment(button1); button2.setLayoutData(formData);//from ww w . j a va2 s . c o m Button button3 = new Button(shell, SWT.PUSH); button3.setText("button3"); formData = new FormData(); formData.top = new FormAttachment(button2, 10); formData.left = new FormAttachment(button2, 0, SWT.LEFT); button3.setLayoutData(formData); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:GridLayoutHORIZONTALALIGNCENTER.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;/*from ww w .j a va 2 s . c o m*/ layout.makeColumnsEqualWidth = true; shell.setLayout(layout); // Create the big button in the upper left GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 200; Button one = new Button(shell, SWT.PUSH); one.setText("one"); one.setLayoutData(data); // Create a composite to hold the three buttons in the upper right Composite composite = new Composite(shell, SWT.NONE); // Create button "three" data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); Button three = new Button(composite, SWT.PUSH); three.setText("three"); three.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ListClass.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 w ww . j a va2 s . c o m final List list = new List(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); list.setBounds(40, 20, 220, 100); 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:ComboSelectionEvent.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" }; final Combo combo = new Combo(shell, SWT.DROP_DOWN); combo.setItems(ITEMS);//from w w w.ja v a 2s . c o m 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()); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ScrolledCompositeMiniSize.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"); sc.setMinSize(400, 400);// w w w . j a v a 2 s .co m // Expand both horizontally and vertically sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setContent(child); 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);/* w w w . jav a 2 s. c om*/ 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:SWTGridLayout.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(300, 200);/*from w ww.j av a 2s . c om*/ shell.setLayout(new RowLayout()); final Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 4; composite.setLayout(gridLayout); for (int loopIndex = 0; loopIndex < 18; loopIndex++) { Button button = new Button(composite, SWT.PUSH); button.setText("Button " + loopIndex); } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollBarExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); // Create a List with a vertical scroll bar List list = new List(shell, SWT.V_SCROLL); // Add a bunch of items to it for (int i = 0; i < 500; i++) { list.add("A list item"); }/*from w ww . ja v a 2 s .c o m*/ // Scroll to the bottom list.select(list.getItemCount() - 1); list.showSelection(); // Get the scroll bar ScrollBar sb = list.getVerticalBar(); // Add one more item that shows the selection value list.add("Selection: " + sb.getSelection()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:GridLayoutAlignmentHoriVerical.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 ww .ja v a 2 s . c om*/ 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.HORIZONTAL_ALIGN_CENTER)); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); button2.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); button3.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutAttachAnotherControl.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"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button2"); FormData formData = new FormData(); formData.left = new FormAttachment(button1); button2.setLayoutData(formData);/*from w ww.j a v a2 s . c om*/ Button button3 = new Button(shell, SWT.PUSH); button3.setText("button3"); formData = new FormData(); formData.top = new FormAttachment(button2, 10); button3.setLayoutData(formData); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }