List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
From source file:SashFormAdvanced.java
/** * Creates the main window's contents// w w w . j av a2 s . c om * * @param parent the parent window */ private void createContents(Composite parent) { // Our layout will have a row of buttons, and // then a SashForm below it. parent.setLayout(new GridLayout(1, false)); // Create the row of buttons Composite buttonBar = new Composite(parent, 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"); // Create the SashForm Composite sash = new Composite(parent, SWT.NONE); sash.setLayout(new FillLayout()); sash.setLayoutData(new GridData(GridData.FILL_BOTH)); final SashForm sashForm = new SashForm(sash, SWT.HORIZONTAL); // Change the width of the sashes sashForm.SASH_WIDTH = 20; // Change the color used to paint the sashes sashForm.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN)); // Create the buttons and their event handlers 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); } }); // Set the relative weights for the buttons sashForm.setWeights(new int[] { 1, 2, 3 }); // Add the Switch Orientation functionality 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; } } }); // Add the Restore Weights functionality weights.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { sashForm.setWeights(new int[] { 1, 2, 3 }); } }); }
From source file:org.eclipse.swt.examples.graphics.LineStyleTab.java
@Override public void createControlPanel(Composite parent) { Composite comp; comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineWidth")); //$NON-NLS-1$ lineWidthSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); lineWidthSpinner.setSelection(10);//from ww w .j a va 2 s .co m lineWidthSpinner.setMinimum(1); lineWidthSpinner.setMaximum(30); lineWidthSpinner.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { lineColor = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the foreground to the 5th item in the menu (blue) lineColor = (GraphicsBackground) menu.getItem(4).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(lineColor.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:Ch11WizardComposite.java
protected void buildControls() { final Composite parent = this; FillLayout layout = new FillLayout(); parent.setLayout(layout); Button dialogBtn = new Button(parent, SWT.PUSH); dialogBtn.setText("Wizard Dialog..."); dialogBtn.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { WizardDialog dialog = new WizardDialog(parent.getShell(), new ProjectWizard()); dialog.open();//from ww w . jav a 2 s .c om } public void widgetDefaultSelected(SelectionEvent e) { } }); }
From source file:org.eclipse.swt.examples.graphics.LineCapTab.java
@Override public void createControlPanel(Composite parent) { Composite comp; // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { foreground = gb;//from ww w . j a va 2s .c o m colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the foreground to the 3rd item in the menu (red) foreground = (GraphicsBackground) menu.getItem(2).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(foreground.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NULL); this.getShell().setText("ButtonTest"); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = 4;//from w w w.ja v a 2 s . c o m layout.verticalSpacing = 9; Label label; label = new Label(container, SWT.NONE); label.setText("Button Type"); label = new Label(container, SWT.NONE); label.setText("NONE"); label = new Label(container, SWT.NONE); label.setText("BORDER"); label = new Label(container, SWT.NONE); label.setText("FLAT"); createLabel(container, SWT.NONE, "Push"); createButton(container, SWT.PUSH, "button1"); createButton(container, SWT.BORDER, "button2"); createButton(container, SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Radio"); createButton(container, SWT.RADIO, "button1"); createButton(container, SWT.RADIO | SWT.BORDER, "button2"); createButton(container, SWT.RADIO | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Toggle"); createButton(container, SWT.TOGGLE, "button1"); createButton(container, SWT.TOGGLE | SWT.BORDER, "button2"); createButton(container, SWT.TOGGLE | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Check"); createButton(container, SWT.CHECK, "button1"); createButton(container, SWT.CHECK | SWT.BORDER, "button2"); createButton(container, SWT.CHECK | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Arrow | Left"); createButton(container, SWT.ARROW | SWT.LEFT, "button1"); createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2"); createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3"); return container; }
From source file:org.eclipse.swt.examples.graphics.GraphicAntialiasTab.java
@Override public void createControlPanel(Composite parent) { Composite comp; // create drop down combo for antialiasing comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$ aliasCombo = new Combo(comp, SWT.DROP_DOWN); aliasCombo.add("OFF"); aliasCombo.add("DEFAULT"); aliasCombo.add("ON"); aliasCombo.select(0);// w w w. j av a 2s .c om aliasCombo.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); menu = cm.createMenu(parent.getParent(), gb -> { ovalColorGB = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the background to the 5th item in the menu (blue) ovalColorGB = (GraphicsBackground) menu.getItem(4).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(ovalColorGB.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button newPerson = new Button(composite, SWT.PUSH); newPerson.setText("Create New Person"); final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION); tv.setContentProvider(new PersonContentProvider()); tv.setLabelProvider(new StudentLabelProvider()); tv.setInput(studentList);/*from www. ja va 2 s . c o m*/ Table table = tv.getTable(); table.setLayoutData(new GridData(GridData.FILL_BOTH)); new TableColumn(table, SWT.CENTER).setText(NAME); new TableColumn(table, SWT.CENTER).setText(MALE); new TableColumn(table, SWT.CENTER).setText(AGE); new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR); for (int i = 0, n = table.getColumnCount(); i < n; i++) { table.getColumn(i).pack(); } table.setHeaderVisible(true); table.setLinesVisible(true); newPerson.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Student p = new Student(); p.setName("Name"); p.setMale(true); p.setAgeRange(Integer.valueOf("0")); p.setShirtColor(new RGB(255, 0, 0)); studentList.add(p); tv.refresh(); } }); CellEditor[] editors = new CellEditor[4]; editors[0] = new TextCellEditor(table); editors[1] = new CheckboxCellEditor(table); editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES, SWT.READ_ONLY); editors[3] = new ColorCellEditor(table); tv.setColumnProperties(PROPS); tv.setCellModifier(new StudentCellModifier(tv)); tv.setCellEditors(editors); return composite; }
From source file:org.eclipse.swt.examples.graphics.PathClippingAnimTab.java
/** * Creates the widgets used to control the drawing. *///from w ww .jav a2s . c o m @Override public void createControlPanel(Composite parent) { super.createControlPanel(parent); // color menu ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { background = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the background to the 5th item in the menu (blue) background = (GraphicsBackground) menu.getItem(4).getData(); // color button Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:PlayerTable.java
/** * Create the contents of the main window * //from ww w . j a va 2 s. c om * @param composite the parent composite */ private void createContents(Composite composite) { composite.setLayout(new FillLayout()); // Create the table final Table table = new Table(composite, SWT.NONE); table.setHeaderVisible(true); table.setLinesVisible(true); // Create each of the columns, adding an event // listener that will set the appropriate fields // into the comparator and then call the fillTable // helper method TableColumn[] columns = new TableColumn[3]; columns[0] = new TableColumn(table, SWT.NONE); columns[0].setText("First Name"); columns[0].addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { comparator.setColumn(PlayerComparator.FIRST_NAME); comparator.reverseDirection(); fillTable(table); } }); columns[1] = new TableColumn(table, SWT.NONE); columns[1].setText("Last Name"); columns[1].addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { comparator.setColumn(PlayerComparator.LAST_NAME); comparator.reverseDirection(); fillTable(table); } }); columns[2] = new TableColumn(table, SWT.RIGHT); columns[2].setText("Batting Average"); columns[2].addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { comparator.setColumn(PlayerComparator.BATTING_AVERAGE); comparator.reverseDirection(); fillTable(table); } }); // Do the initial fill of the table fillTable(table); // Pack each column so inital display is good for (int i = 0, n = columns.length; i < n; i++) { columns[i].pack(); } }
From source file:CoolBarExamples.java
public CoolBarExamples() { shell.setLayout(new GridLayout()); final CoolBar coolBar = new CoolBar(shell, SWT.NONE); coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // cool item with a text field. CoolItem textItem = new CoolItem(coolBar, SWT.NONE); Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN); text.setText("TEXT"); text.pack();/*from w w w.java 2 s. c om*/ Point size = text.getSize(); textItem.setControl(text); textItem.setSize(textItem.computeSize(size.x, size.y)); // cool item with a label. CoolItem labelItem = new CoolItem(coolBar, SWT.NONE); Label label = new Label(coolBar, SWT.NONE); label.setText("LABEL"); label.pack(); size = label.getSize(); labelItem.setControl(label); labelItem.setSize(textItem.computeSize(size.x, size.y)); // cool item with a button. CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN); Composite composite = new Composite(coolBar, SWT.NONE); composite.setLayout(new GridLayout(2, true)); Button button1 = new Button(composite, SWT.PUSH); button1.setText("Button 1"); button1.pack(); Button button2 = new Button(composite, SWT.PUSH); button2.setText("Button 2"); button2.pack(); composite.pack(); size = composite.getSize(); buttonItem.setControl(composite); buttonItem.setSize(buttonItem.computeSize(size.x, size.y)); // // Test cool item adding method. // Label label2 = new Label(coolBar, SWT.NONE); // label2.setText("label2"); // addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar); try { setState(coolBar, new File("coolbar.state")); } catch (IOException e1) { e1.printStackTrace(); } shell.addListener(SWT.Close, new Listener() { public void handleEvent(Event event) { try { saveState(coolBar, new File("coolbar.state")); } catch (IOException e) { e.printStackTrace(); } } }); shell.setSize(300, 120); // shell.pack(); shell.open(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }