List of usage examples for org.eclipse.swt.widgets Composite Composite
public Composite(Composite parent, int style)
From source file:ExpandBarControlsAdding.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;/*www.j a v a 2 s.c o m*/ composite.setLayout(layout); Button button = new Button(composite, SWT.PUSH); button.setText("SWT.PUSH"); button = new Button(composite, SWT.RADIO); button.setText("SWT.RADIO"); button = new Button(composite, SWT.CHECK); button.setText("SWT.CHECK"); button = new Button(composite, SWT.TOGGLE); button.setText("SWT.TOGGLE"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file:Snippet46.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); final Composite composite = new Composite(shell, SWT.NONE); composite.setEnabled(false);/*from ww w . ja v a 2 s. c om*/ 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 = new Listener() { public void handleEvent(Event 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:ExpandBarIconAddingSystem.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;//from w ww. java 2 s. c om composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
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);// ww w . j a v a 2s .c o m shell.setLayout(new GridLayout(1, false)); Composite buttonBar = new Composite(shell, SWT.NONE); buttonBar.setLayout(new RowLayout()); Button flip = new Button(buttonBar, SWT.PUSH); flip.setText("Switch Orientation"); Button weights = new Button(buttonBar, SWT.PUSH); weights.setText("Restore Weights"); 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"); final Button two = new Button(sashForm, SWT.PUSH); two.setText("Two"); final Button three = new Button(sashForm, SWT.PUSH); three.setText("Three"); sashForm.setWeights(new int[] { 2, 2, 2 }); flip.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { switch (sashForm.getOrientation()) { case SWT.HORIZONTAL: sashForm.setOrientation(SWT.VERTICAL); break; case SWT.VERTICAL: sashForm.setOrientation(SWT.HORIZONTAL); break; } } }); weights.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { sashForm.setWeights(new int[] { 2, 2, 2 }); } }); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file: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); final Composite composite = new Composite(shell, SWT.BORDER); composite.setSize(200, 400);/* w ww. j a v a 2s. c o m*/ final ScrollBar hBar = shell.getHorizontalBar(); hBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = composite.getLocation(); location.x = -hBar.getSelection(); composite.setLocation(location); } }); final ScrollBar vBar = shell.getVerticalBar(); vBar.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Point location = composite.getLocation(); location.y = -vBar.getSelection(); composite.setLocation(location); } }); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event 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.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TabItemWithComposite.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); final TabFolder tabFolder = new TabFolder(shell, SWT.BORDER); for (int i = 0; i < 6; i++) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("TabItem " + i); item.setToolTipText("This is my tab" + i); item.setImage(new Image(display, "yourFile.gif")); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new FillLayout()); new Button(composite, SWT.PUSH).setText("Button One"); new Button(composite, SWT.PUSH).setText("Button Two"); new Button(composite, SWT.PUSH).setText("Button Three"); item.setControl(composite);// www. jav a2 s .c o m } tabFolder.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CoolBarCombo.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); CoolBar coolBar = new CoolBar(shell, SWT.BORDER); coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final CoolItem item = new CoolItem(coolBar, SWT.DROP_DOWN); Composite c = new Composite(coolBar, SWT.NONE); c.setLayout(new FillLayout()); Combo combo = new Combo(c, SWT.DROP_DOWN); combo.add("Option One"); combo.add("Option Two"); combo.add("Option Three"); item.setControl(c);/*from w ww . j a v a 2s . c o m*/ Control control = item.getControl(); Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); pt = item.computeSize(pt.x, pt.y); item.setSize(pt); coolBar.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet154.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED); /*//from w ww .j a v a 2 s . c om * Set a Windows specific AWT property that prevents heavyweight * components from erasing their background. Note that this is a global * property and cannot be scoped. It might not be suitable for your * application. */ try { System.setProperty("sun.awt.noerasebackground", "true"); } catch (NoSuchMethodError error) { } /* Create and setting up frame */ Frame frame = SWT_AWT.new_Frame(composite); Panel panel = new Panel(new BorderLayout()) { public void update(java.awt.Graphics g) { /* Do not erase the background */ paint(g); } }; frame.add(panel); JRootPane root = new JRootPane(); panel.add(root); java.awt.Container contentPane = root.getContentPane(); /* Creating components */ int nrows = 1000, ncolumns = 10; Vector rows = new Vector(); for (int i = 0; i < nrows; i++) { Vector row = new Vector(); for (int j = 0; j < ncolumns; j++) { row.addElement("Item " + i + "-" + j); } rows.addElement(row); } Vector columns = new Vector(); for (int i = 0; i < ncolumns; i++) { columns.addElement("Column " + i); } JTable table = new JTable(rows, columns); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.createDefaultColumnsFromModel(); JScrollPane scrollPane = new JScrollPane(table); contentPane.setLayout(new BorderLayout()); contentPane.add(scrollPane); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(250, 200);/* w ww . j a v a 2 s . c o m*/ shell.setLayout(new FormLayout()); Composite controls = new Composite(shell, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); controls.setLayoutData(data); final Browser browser = new Browser(shell, SWT.NONE); data = new FormData(); data.top = new FormAttachment(controls); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); browser.setLayoutData(data); controls.setLayout(new GridLayout(6, false)); Button button = new Button(controls, SWT.PUSH); button.setText("Back"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.back(); } }); button = new Button(controls, SWT.PUSH); button.setText("Forward"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.forward(); } }); button = new Button(controls, SWT.PUSH); button.setText("Refresh"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.refresh(); } }); button = new Button(controls, SWT.PUSH); button.setText("Stop"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.stop(); } }); final Text url = new Text(controls, SWT.BORDER); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.setFocus(); button = new Button(controls, SWT.PUSH); button.setText("Go"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.setUrl(url.getText()); } }); shell.setDefaultButton(button); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutFillBoth.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 v a 2 s .com*/ 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 "two" data = new GridData(GridData.FILL_BOTH); Button two = new Button(composite, SWT.PUSH); two.setText("two"); two.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }