List of usage examples for org.eclipse.swt.widgets Composite Composite
public Composite(Composite parent, int style)
From source file:org.eclipse.swt.snippets.Snippet40.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 40"); shell.setLayout(new GridLayout(2, false)); Composite c1 = new Composite(shell, SWT.BORDER); c1.setLayoutData(new GridData(100, 100)); Composite c2 = new Composite(shell, SWT.BORDER); c2.setLayoutData(new GridData(100, 100)); Menu menu = new Menu(shell, SWT.POP_UP); MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Popup"); c1.setMenu(menu);/* w ww . ja v a 2 s .c o m*/ c2.setMenu(menu); shell.setMenu(menu); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet6.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 6"); shell.setLayout(new GridLayout()); final Composite c = new Composite(shell, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 3;/*w w w . jav a2s . co m*/ c.setLayout(layout); for (int i = 0; i < 10; i++) { Button b = new Button(c, SWT.PUSH); b.setText("Button " + i); } Button b = new Button(shell, SWT.PUSH); b.setText("add a new button at row 2 column 1"); final int[] index = new int[1]; b.addListener(SWT.Selection, e -> { Button s = new Button(c, SWT.PUSH); s.setText("Special " + index[0]); index[0]++; Control[] children = c.getChildren(); s.moveAbove(children[3]); shell.layout(new Control[] { s }); }); 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 . j a v a2 s . com*/ 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(); }
From source file:org.eclipse.swt.snippets.Snippet46.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 46"); final Composite composite = new Composite(shell, SWT.NONE); composite.setEnabled(false);//from w ww.j a va 2 s . c o m composite.setLayout(new FillLayout()); Button button = new Button(composite, SWT.PUSH); button.setText("Button"); composite.pack(); composite.setLocation(10, 10); final Point[] offset = new Point[1]; Listener listener = event -> { switch (event.type) { case SWT.MouseDown: Rectangle rect = composite.getBounds(); if (rect.contains(event.x, event.y)) { Point pt1 = composite.toDisplay(0, 0); Point pt2 = shell.toDisplay(event.x, event.y); offset[0] = new Point(pt2.x - pt1.x, pt2.y - pt1.y); } break; case SWT.MouseMove: if (offset[0] != null) { Point pt = offset[0]; composite.setLocation(event.x - pt.x, event.y - pt.y); } break; case SWT.MouseUp: offset[0] = null; break; } }; shell.addListener(SWT.MouseDown, listener); shell.addListener(SWT.MouseUp, listener); shell.addListener(SWT.MouseMove, listener); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet9.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.H_SCROLL | SWT.V_SCROLL); shell.setText("Snippet 9"); final Composite composite = new Composite(shell, SWT.BORDER); composite.setSize(700, 600);//from w w w . ja v a 2 s . c o m final Color red = display.getSystemColor(SWT.COLOR_RED); composite.addPaintListener(e -> { e.gc.setBackground(red); e.gc.fillOval(5, 5, 690, 590); }); final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, e -> { Point location = composite.getLocation(); location.x = -hBar.getSelection(); composite.setLocation(location); }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, e -> { Point location = composite.getLocation(); location.y = -vBar.getSelection(); composite.setLocation(location); }); shell.addListener(SWT.Resize, e -> { Point size = composite.getSize(); Rectangle rect = shell.getClientArea(); hBar.setMaximum(size.x); vBar.setMaximum(size.y); hBar.setThumb(Math.min(size.x, rect.width)); vBar.setThumb(Math.min(size.y, rect.height)); int hPage = size.x - rect.width; int vPage = size.y - rect.height; int hSelection = hBar.getSelection(); int vSelection = vBar.getSelection(); Point location = composite.getLocation(); if (hSelection >= hPage) { if (hPage <= 0) hSelection = 0; location.x = -hSelection; } if (vSelection >= vPage) { if (vPage <= 0) vSelection = 0; location.y = -vSelection; } composite.setLocation(location); }); shell.setSize(600, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ControlEditorSample.java
public static void main(String[] args) { final Shell shell = new Shell(display); shell.setText("Control Editor"); final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color);// ww w . jav a2 s. c om composite.setBounds(0, 0, 300, 100); ControlEditor editor = new ControlEditor(composite); final Text text = new Text(composite, SWT.BORDER); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { RGB rgb = (RGB) COLORS.get(text.getText()); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor in the top middle of the parent composite editor.horizontalAlignment = SWT.CENTER; editor.verticalAlignment = SWT.TOP; Point size = text.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumWidth = size.x; editor.minimumHeight = size.y; editor.setEditor(text); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } if (color != null) color.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet77.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 77"); 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);//from w w w. j a v a 2 s . 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(ControlListener.controlResizedAdapter(e -> { Rectangle area = comp.getClientArea(); Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); ScrollBar vBar = table.getVerticalBar(); int width = area.width - table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x; if (size.y > area.height + table.getHeaderHeight()) { // Subtract the scrollbar width from the total column width // if a vertical scrollbar will be required Point vBarSize = vBar.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:org.eclipse.swt.snippets.Snippet109.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 109"); shell.setLayout(new FillLayout()); SashForm form = new SashForm(shell, SWT.HORIZONTAL); form.setLayout(new FillLayout()); Composite child1 = new Composite(form, SWT.NONE); child1.setLayout(new FillLayout()); new Label(child1, SWT.NONE).setText("Label in pane 1"); Composite child2 = new Composite(form, SWT.NONE); child2.setLayout(new FillLayout()); new Button(child2, SWT.PUSH).setText("Button in pane2"); Composite child3 = new Composite(form, SWT.NONE); child3.setLayout(new FillLayout()); new Label(child3, SWT.PUSH).setText("Label in pane3"); form.setWeights(new int[] { 30, 40, 30 }); shell.open();//from w w w .j a va 2 s .c o m while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet155.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 155"); shell.setLayout(new FillLayout()); Composite composite = new Composite(shell, SWT.EMBEDDED); /* Draw an X using AWT */ Frame frame = SWT_AWT.new_Frame(composite); Canvas canvas = new Canvas() { @Override//w ww .j a va 2 s .com public void paint(Graphics g) { Dimension d = getSize(); g.drawLine(0, 0, d.width, d.height); g.drawLine(d.width, 0, 0, d.height); } }; frame.add(canvas); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet98.java
public static void main(String args[]) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 98"); shell.setLayout(new GridLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Push"); pageComposite = new Composite(shell, SWT.NONE); pageComposite.setLayout(new GridLayout()); pageComposite.setLayoutData(new GridData()); button.addListener(SWT.Selection, event -> { if ((pageComposite != null) && (!pageComposite.isDisposed())) { pageComposite.dispose();/*from w w w .j ava2 s . co m*/ } pageComposite = new Composite(shell, SWT.NONE); pageComposite.setLayout(new GridLayout()); pageComposite.setLayoutData(new GridData()); if (pageNum++ % 2 == 0) { Table table = new Table(pageComposite, SWT.BORDER); table.setLayoutData(new GridData()); for (int i = 0; i < 5; i++) { new TableItem(table, SWT.NONE).setText("table item " + i); } } else { new Button(pageComposite, SWT.RADIO).setText("radio"); } shell.layout(true); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }