List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
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 ww . j a v a 2 s . com*/ * 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 w w. j a v a2 s. c om*/ 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:JavascriptExec.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) { /* Script may fail or may not be supported on certain platforms. */ System.out.println("Script was not executed."); }//w ww .ja v a 2 s. c om } }); browser.setText(html); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet161.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.setText("Snippet 161"); shell.setLayout(new FillLayout()); final Browser browser; try {//from w w w . ja v a2 s . c o m browser = new Browser(shell, SWT.BORDER); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } 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, event -> { boolean result = browser.execute(text.getText()); if (!result) { /* 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:ControlListenerAdd.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout()); final Composite composite = new Composite(shell, SWT.BORDER); composite.setLayout(new RowLayout()); composite.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); composite.addControlListener(new ControlListener() { public void controlMoved(ControlEvent e) { }/*from w w w .j a v a2s . c o m*/ public void controlResized(ControlEvent e) { System.out.println("Composite resize."); } }); Button buttonAdd = new Button(shell, SWT.PUSH); buttonAdd.setText("Add new button"); buttonAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button button = new Button(composite, SWT.PUSH); button.setText("Button #" + (count++)); composite.layout(true); composite.pack(); } }); shell.setSize(450, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FocusTraversal.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setLayout(new RowLayout()); composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); Button button1 = new Button(composite1, SWT.PUSH); button1.setText("Button1"); Button button3 = new Button(composite1, SWT.PUSH); button3.setText("Button3"); Button radioButton1 = new Button(composite1, SWT.RADIO); radioButton1.setText("radio-1"); Button radioButton2 = new Button(composite1, SWT.RADIO); radioButton2.setText("radio-2"); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new RowLayout()); composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); Button button2 = new Button(composite2, SWT.PUSH); button2.setText("Button2"); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0);//from w w w. ja v a2s .c o m composite1.setTabList(new Control[] { button1, button3 }); composite2.setTabList(new Control[] { button2, combo }); shell.setTabList(new Control[] { composite2, composite1 }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
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 www.ja v a 2 s . c o m*/ shell.setLayout(new GridLayout(1, false)); Composite sash = new Composite(shell, SWT.NONE); sash.setLayout(new FillLayout()); sash.setLayoutData(new GridData(GridData.FILL_BOTH)); final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL); sashForm.SASH_WIDTH = 5; sashForm.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE)); final Button one = new Button(sashForm, SWT.PUSH); one.setText("One"); one.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(one, sashForm); } }); final Button two = new Button(sashForm, SWT.PUSH); two.setText("Two"); two.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(two, sashForm); } }); final Button three = new Button(sashForm, SWT.PUSH); three.setText("Three"); three.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { maximizeHelper(three, sashForm); } }); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:Snippet115.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout(SWT.VERTICAL)); Composite c1 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP); c1.setLayout(new RowLayout()); Composite c2 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP); c2.setLayout(new RowLayout()); final Composite[] composites = new Composite[] { c1, c2 }; Listener radioGroup = new Listener() { public void handleEvent(Event event) { for (int i = 0; i < composites.length; i++) { Composite composite = composites[i]; Control[] children = composite.getChildren(); for (int j = 0; j < children.length; j++) { Control child = children[j]; if (child instanceof Button) { Button button = (Button) child; if ((button.getStyle() & SWT.RADIO) != 0) button.setSelection(false); }//from w w w . j av a 2 s.c om } } Button button = (Button) event.widget; button.setSelection(true); } }; for (int i = 0; i < 4; i++) { Button button = new Button(c1, SWT.RADIO); button.setText("Button " + i); button.addListener(SWT.Selection, radioGroup); } for (int i = 0; i < 4; i++) { Button button = new Button(c2, SWT.RADIO); button.setText("Button " + (i + 4)); button.addListener(SWT.Selection, radioGroup); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollWidgetViewFocusIn.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Button b1 = new Button(shell, SWT.PUSH); b1.setText("top"); b1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); Composite c = new Composite(sc, SWT.NONE); c.setLayout(new GridLayout(10, true)); for (int i = 0; i < 300; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); }/*from ww w . jav a 2 s. co m*/ Button b2 = new Button(shell, SWT.PUSH); b2.setText("bottom"); b2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); sc.setContent(c); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT)); Listener listener = new Listener() { public void handleEvent(Event e) { Control child = (Control) e.widget; Rectangle bounds = child.getBounds(); Rectangle area = sc.getClientArea(); Point origin = sc.getOrigin(); if (origin.x > bounds.x) origin.x = Math.max(0, bounds.x); if (origin.y > bounds.y) origin.y = Math.max(0, bounds.y); if (origin.x + area.width < bounds.x + bounds.width) origin.x = Math.max(0, bounds.x + bounds.width - area.width); if (origin.y + area.height < bounds.y + bounds.height) origin.y = Math.max(0, bounds.y + bounds.height - area.height); sc.setOrigin(origin); } }; Control[] controls = c.getChildren(); for (int i = 0; i < controls.length; i++) { controls[i].addListener(SWT.Activate, listener); } shell.setSize(300, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet115.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 115"); shell.setLayout(new RowLayout(SWT.VERTICAL)); Composite c1 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP); c1.setLayout(new RowLayout()); Composite c2 = new Composite(shell, SWT.BORDER | SWT.NO_RADIO_GROUP); c2.setLayout(new RowLayout()); final Composite[] composites = new Composite[] { c1, c2 }; Listener radioGroup = event -> {/*from w ww. jav a 2 s. co m*/ for (int i = 0; i < composites.length; i++) { Composite composite = composites[i]; Control[] children = composite.getChildren(); for (int j = 0; j < children.length; j++) { Control child = children[j]; if (child instanceof Button) { Button button1 = (Button) child; if ((button1.getStyle() & SWT.RADIO) != 0) button1.setSelection(false); } } } Button button2 = (Button) event.widget; button2.setSelection(true); }; for (int i = 0; i < 4; i++) { Button button = new Button(c1, SWT.RADIO); button.setText("Button " + i); button.addListener(SWT.Selection, radioGroup); } for (int i = 0; i < 4; i++) { Button button = new Button(c2, SWT.RADIO); button.setText("Button " + (i + 4)); button.addListener(SWT.Selection, radioGroup); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }