List of usage examples for org.eclipse.swt.widgets Composite Composite
public Composite(Composite parent, int style)
From source file:GridLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;/*from w w w. j a v a2 s. c om*/ 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); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; composite.setLayoutData(data); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 15; composite.setLayout(layout); shell.pack(); 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 om*/ 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:Snippet75.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Composite c1 = new Composite(shell, SWT.BORDER); c1.setLayout(new RowLayout()); Button b1 = new Button(c1, SWT.PUSH); b1.setText("B1"); Button[] radios = new Button[3]; for (int i = 0; i < radios.length; i++) { radios[i] = new Button(c1, SWT.RADIO); radios[i].setText("R" + (i == 1 ? "&" : "") + i); }/* ww w.j a v a 2 s . c o m*/ Button b2 = new Button(c1, SWT.PUSH); b2.setText("B2"); List l1 = new List(c1, SWT.SINGLE | SWT.BORDER); l1.setItems(new String[] { "L1" }); Button b3 = new Button(c1, SWT.PUSH); b3.setText("B&3"); Button b3_1 = new Button(c1, SWT.PUSH); b3_1.setText("B3_1"); Composite c2 = new Composite(shell, SWT.BORDER); c2.setLayout(new RowLayout()); Button b4 = new Button(c2, SWT.PUSH); b4.setText("B&4"); Button b5 = new Button(c2, SWT.PUSH); b5.setText("B&5"); List l2 = new List(shell, SWT.SINGLE | SWT.BORDER); l2.setItems(new String[] { "L2" }); ToolBar tb1 = new ToolBar(shell, SWT.FLAT | SWT.BORDER); ToolItem i1 = new ToolItem(tb1, SWT.RADIO); i1.setText("I1"); ToolItem i2 = new ToolItem(tb1, SWT.RADIO); i2.setText("I&2"); Combo combo1 = new Combo(tb1, SWT.READ_ONLY | SWT.BORDER); combo1.setItems(new String[] { "C1" }); combo1.setText("C1"); combo1.pack(); ToolItem i3 = new ToolItem(tb1, SWT.SEPARATOR); i3.setWidth(combo1.getSize().x); i3.setControl(combo1); i3.setText("I3"); ToolItem i4 = new ToolItem(tb1, SWT.PUSH); i4.setText("I4"); ToolItem i5 = new ToolItem(tb1, SWT.CHECK); i5.setText("I5"); Button b6 = new Button(shell, SWT.PUSH); b6.setText("B&6"); Composite c4 = new Composite(shell, SWT.BORDER); c4.setSize(32, 32); Composite c5 = new Composite(c4, SWT.BORDER); c5.setSize(20, 20); Control[] list1 = new Control[] { b2, b1, b3_1, b3 }; c1.setTabList(list1); Control[] list2 = new Control[] { c1, b6, tb1, c4, c2, l2 }; shell.setTabList(list2); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet77.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Composite comp = new Composite(shell, SWT.NONE); final Table table = new Table(comp, SWT.BORDER | SWT.V_SCROLL); table.setHeaderVisible(true);//ww w . j a v a 2s . c o m table.setLinesVisible(true); final TableColumn column1 = new TableColumn(table, SWT.NONE); column1.setText("Column 1"); final TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setText("Column 2"); for (int i = 0; i < 10; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "item 0" + i, "item 1" + i }); } comp.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { Rectangle area = comp.getClientArea(); Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); int width = area.width - 2 * table.getBorderWidth(); if (preferredSize.y > area.height + table.getHeaderHeight()) { // Subtract the scrollbar width from the total column width // if a vertical scrollbar will be required Point vBarSize = table.getVerticalBar().getSize(); width -= vBarSize.x; } Point oldSize = table.getSize(); if (oldSize.x > area.width) { // table is getting smaller so make the columns // smaller first and then resize the table to // match the client area width column1.setWidth(width / 3); column2.setWidth(width - column1.getWidth()); table.setSize(area.width, area.height); } else { // table is getting bigger so make the table // bigger first and then make the columns wider // to match the client area width table.setSize(area.width, area.height); column1.setWidth(width / 3); column2.setWidth(width - column1.getWidth()); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;/*from w w w . j a v a 2s. 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); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; composite.setLayoutData(data); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 15; composite.setLayout(layout); // Create button "two" data = new GridData(GridData.FILL_BOTH); Button two = new Button(composite, SWT.PUSH); two.setText("two"); two.setLayoutData(data); // Create button "three" data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); Button three = new Button(composite, SWT.PUSH); three.setText("three"); three.setLayoutData(data); // Create button "four" data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); Button four = new Button(composite, SWT.PUSH); four.setText("four"); four.setLayoutData(data); // Create the long button across the bottom data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; data.horizontalSpan = 3; data.heightHint = 150; Button five = new Button(shell, SWT.PUSH); five.setText("five"); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ModifyDOM.java
public static void main(String[] args) { final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>"; Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Browser browser = new Browser(shell, SWT.BORDER); Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new FillLayout(SWT.VERTICAL)); final Text text = new Text(comp, SWT.MULTI); text.setText("var newNode = document.createElement('P'); \r\n" + "var text = document.createTextNode('At least when I am around');\r\n" + "newNode.appendChild(text);\r\n" + "document.getElementById('myid').appendChild(newNode);\r\n" + "\r\n" + "document.bgColor='yellow';"); final Button button = new Button(comp, SWT.PUSH); button.setText("Execute Script"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { boolean result = browser.execute(text.getText()); if (!result) { /*// w w w. j a va 2 s . co m * Script may fail or may not be supported on certain * platforms. */ System.out.println("Script was not executed."); } } }); browser.setText(html); 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.setText("A Tabbed Shell Example"); s.setLayout(new FillLayout()); TabFolder tf = new TabFolder(s, SWT.BORDER); TabItem ti1 = new TabItem(tf, SWT.BORDER); ti1.setText("Option Group"); ti1.setControl(new Text(tf, SWT.MULTI)); TabItem ti2 = new TabItem(tf, SWT.BORDER); ti2.setText("Grid"); ti2.setControl(new Text(tf, SWT.MULTI)); TabItem ti3 = new TabItem(tf, SWT.BORDER); ti3.setText("Text"); Composite c1 = new Composite(tf, SWT.BORDER); c1.setLayout(new FillLayout()); Text t = new Text(c1, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); ti3.setControl(c1);//from w ww . j a va2 s .com TabItem ti4 = new TabItem(tf, SWT.BORDER); ti4.setText("Settings"); Composite c2 = new Composite(tf, SWT.BORDER); c2.setLayout(new RowLayout()); Text t2 = new Text(c2, SWT.BORDER | SWT.SINGLE | SWT.WRAP | SWT.V_SCROLL); Button b = new Button(c2, SWT.PUSH | SWT.BORDER); b.setText("Save"); ti4.setControl(c2); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);// w w w . java 2 s.c om Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 20; gridLayout.marginWidth = 20; composite.setLayout(gridLayout); Button two = new Button(composite, SWT.PUSH); two.setText("two"); GridData gridData = new GridData(GridData.FILL_BOTH); two.setLayoutData(gridData); Button three = new Button(composite, SWT.PUSH); three.setText("three"); gridData = new GridData(GridData.FILL_HORIZONTAL); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); data = new FormData(); data.top = new FormAttachment(0, 15); data.left = new FormAttachment(one, 25); data.bottom = new FormAttachment(50, -15); data.right = new FormAttachment(100, -25); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet238.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 238"); Composite composite = new Composite(shell, SWT.BORDER); Rectangle clientArea = shell.getClientArea(); composite.setBounds(clientArea.x, clientArea.y, 100, 100); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item1 = new MenuItem(menu, SWT.PUSH); item1.setText("Push Item"); MenuItem item2 = new MenuItem(menu, SWT.CASCADE); item2.setText("Cascade Item"); Menu subMenu = new Menu(menu); item2.setMenu(subMenu);// w w w. j a v a 2 s.c o m MenuItem subItem1 = new MenuItem(subMenu, SWT.PUSH); subItem1.setText("Subitem 1"); MenuItem subItem2 = new MenuItem(subMenu, SWT.PUSH); subItem2.setText("Subitem 2"); composite.setMenu(menu); shell.setMenu(menu); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);/*from ww w . j a v a 2 s . c o m*/ Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; composite.setLayout(gridLayout); Button two = new Button(composite, SWT.PUSH); two.setText("two"); GridData gridData = new GridData(GridData.FILL_BOTH); two.setLayoutData(gridData); Button three = new Button(composite, SWT.PUSH); three.setText("three"); gridData = new GridData(GridData.FILL_BOTH); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(one, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(100, -5); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }