List of usage examples for org.eclipse.swt.widgets Composite setLayout
public void setLayout(Layout layout)
From source file:MainClass.java
protected Control createDialogArea(Composite parent) { createMessageArea(parent);// www . jav a 2s. c o m Composite composite = new Composite(parent, SWT.NONE); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; composite.setLayoutData(data); composite.setLayout(new FillLayout()); label = new Label(composite, SWT.LEFT); return composite; }
From source file:Ch11WizardComposite.java
public void createControl(Composite parent) { Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new FillLayout()); textLabel = new Label(topLevel, SWT.CENTER); textLabel.setText(""); setControl(topLevel);//w ww .j av a 2 s. co m setPageComplete(true); }
From source file:ControlSizeLocation.java
private void init() { GridLayout gridLayout = new GridLayout(2, true); shell.setLayout(gridLayout);/*from ww w.j av a 2 s . com*/ Composite left = new Composite(shell, SWT.NULL); left.setLayout(new GridLayout()); //left.setLayout(new FillLayout()); left.setLayoutData(new GridData(GridData.FILL_BOTH)); left.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); button = new Button(left, SWT.PUSH); button.setText("Button"); button.setLayoutData(new GridData()); Composite right = new Composite(shell, SWT.NULL); right.setLayout(new GridLayout(4, true)); right.setLayoutData(new GridData(GridData.FILL_BOTH)); Label label = new Label(right, SWT.NULL); label.setText("X"); label = new Label(right, SWT.NULL); label.setText("Y"); label = new Label(right, SWT.NULL); label.setText("Width"); label = new Label(right, SWT.NULL); label.setText("Height"); x = new Text(right, SWT.BORDER); y = new Text(right, SWT.BORDER); w = new Text(right, SWT.BORDER); h = new Text(right, SWT.BORDER); SelectionListener selectionListener = new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b == get) { System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); } else if (b == set) { int vx = getNumber(x); int vy = getNumber(y); int vw = getNumber(w); int vh = getNumber(h); if (vx != -1 && vy != -1) { if (vw != -1 && vh != -1) { Rectangle rectangle = new Rectangle(vx, vy, vw, vh); button.setBounds(rectangle); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setBounds: " + rectangle); } else { Point point = new Point(vx, vy); button.setLocation(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setLocation: " + point); } } else if (vw != -1 && vh != -1) { Point point = new Point(vw, vh); button.setSize(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setSize: " + point); } } } public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }; get = new Button(right, SWT.PUSH); get.setText("Get"); get.addSelectionListener(selectionListener); set = new Button(right, SWT.PUSH); set.setText("Set"); set.addSelectionListener(selectionListener); }
From source file:Ch11WizardComposite.java
public void createControl(Composite parent) { Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout(2, false)); Label l = new Label(topLevel, SWT.CENTER); l.setText("Use default directory?"); button = new Button(topLevel, SWT.CHECK); setControl(topLevel);/*from w ww . jav a 2s. c o m*/ setPageComplete(true); }
From source file:Ch11WizardComposite.java
public void createControl(Composite parent) { Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout(2, false)); Label l = new Label(topLevel, SWT.CENTER); l.setText("Enter the directory to use:"); text = new Text(topLevel, SWT.SINGLE); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); setControl(topLevel);/*from www .j a v a 2 s.c om*/ setPageComplete(true); }
From source file:org.eclipse.swt.examples.graphics.SpiralTab.java
/** * This method creates a spinner for specifying the number of petals. The call to the * createControlPanel method in the super class create the controls that are * defined in the super class./*from w w w . j ava 2s . co m*/ * * @param parent The parent composite */ @Override public void createControlPanel(Composite parent) { super.createControlPanel(parent); // create spinner number of petals Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Petals")); //$NON-NLS-1$ petalSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); petalSpinner.setSelection(8); petalSpinner.setMinimum(3); petalSpinner.setMaximum(20); petalSpinner.addListener(SWT.Selection, event -> example.redraw()); // 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; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the foreground to the 2nd item in the menu foreground = (GraphicsBackground) menu.getItem(1).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:DialogExamples.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new GridLayout()); /* ------ MessageDialog ------------- */ // openQuestion final Button buttonOpenMessage = new Button(composite, SWT.PUSH); buttonOpenMessage.setText("Demo: MessageDialog.openQuestion"); buttonOpenMessage.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { boolean answer = MessageDialog.openQuestion(getShell(), "A Simple Question", "Is SWT/JFace your favorite Java UI framework?"); System.out.println("Your answer is " + (answer ? "YES" : "NO")); }/*from w ww . j a v a 2s .c o m*/ }); final Button buttonMessageDialog = new Button(composite, SWT.PUSH); buttonMessageDialog.setText("Demo: new MessageDialog"); buttonMessageDialog.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { MessageDialog dialog = new MessageDialog(getShell(), "Select your favorite Java UI framework", null, "Which one of the following is your favorite Java UI framework?", MessageDialog.QUESTION, new String[] { "AWT", "Swing", "SWT/JFace" }, 2); int answer = dialog.open(); switch (answer) { case -1: // if the user closes the dialog without clicking any button. System.out.println("No selection"); break; case 0: System.out.println("Your selection is: AWT"); break; case 1: System.out.println("Your selection is: Swing"); break; case 2: System.out.println("Your selection is: SWT/JFace"); break; } } }); /* ------ InputDialog ------------- */ final Button buttonInputDialog = new Button(composite, SWT.PUSH); buttonInputDialog.setText("Demo: InputDialog"); buttonInputDialog.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { IInputValidator validator = new IInputValidator() { public String isValid(String newText) { if (newText.equalsIgnoreCase("SWT/JFace") || newText.equalsIgnoreCase("AWT") || newText.equalsIgnoreCase("Swing")) return null; else return "The allowed values are: SWT/JFace, AWT, Swing"; } }; InputDialog dialog = new InputDialog(getShell(), "Question", "What's your favorite Java UI framework?", "SWT/JFace", validator); if (dialog.open() == Window.OK) { System.out.println("Your favorite Java UI framework is: " + dialog.getValue()); } else { System.out.println("Action cancelled"); } } }); /* ------ ProgressMonitorDialog ------------- */ final Button buttonProgressDialog = new Button(composite, SWT.PUSH); buttonProgressDialog.setText("Demo: ProgressMonitorDialog"); buttonProgressDialog.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Number counting", 10); for (int i = 0; i < 10; i++) { if (monitor.isCanceled()) { monitor.done(); return; } System.out.println("Count number: " + i); monitor.worked(1); Thread.sleep(500); // 0.5s. } monitor.done(); } }; ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try { dialog.run(true, true, runnableWithProgress); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); return super.createContents(parent); }
From source file:org.eclipse.swt.examples.controlexample.ExpandBarTab.java
/** * Creates the "Example" widgets.//www . ja v a 2 s.co m */ @Override void createExampleWidgets() { /* Compute the widget style */ int style = getDefaultStyle(); if (borderButton.getSelection()) style |= SWT.BORDER; if (verticalButton.getSelection()) style |= SWT.V_SCROLL; /* Create the example widgets */ expandBar1 = new ExpandBar(expandBarGroup, style); // First item Composite composite = new Composite(expandBar1, SWT.NONE); composite.setLayout(new GridLayout()); new Button(composite, SWT.PUSH).setText("SWT.PUSH"); new Button(composite, SWT.RADIO).setText("SWT.RADIO"); new Button(composite, SWT.CHECK).setText("SWT.CHECK"); new Button(composite, SWT.TOGGLE).setText("SWT.TOGGLE"); ExpandItem item = new ExpandItem(expandBar1, SWT.NONE, 0); item.setText(ControlExample.getResourceString("Item1_Text")); item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item.setControl(composite); item.setImage(instance.images[ControlExample.ciClosedFolder]); // Second item composite = new Composite(expandBar1, SWT.NONE); composite.setLayout(new GridLayout(2, false)); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_ERROR)); new Label(composite, SWT.NONE).setText("SWT.ICON_ERROR"); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_INFORMATION)); new Label(composite, SWT.NONE).setText("SWT.ICON_INFORMATION"); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_WARNING)); new Label(composite, SWT.NONE).setText("SWT.ICON_WARNING"); new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_QUESTION)); new Label(composite, SWT.NONE).setText("SWT.ICON_QUESTION"); item = new ExpandItem(expandBar1, SWT.NONE, 1); item.setText(ControlExample.getResourceString("Item2_Text")); item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item.setControl(composite); item.setImage(instance.images[ControlExample.ciOpenFolder]); item.setExpanded(true); }
From source file:org.jfree.experimental.chart.swt.editor.SWTChartEditor.java
/** * Creates a new editor./* ww w .ja v a 2s . c o m*/ * * @param shell2 the display. * @param chart2edit the chart to edit. */ public SWTChartEditor(Shell shell2, JFreeChart chart2edit) { this.shell = new Shell(Display.getDefault(), SWT.DIALOG_TRIM); this.shell.setSize(400, 500); this.chart = chart2edit; this.shell.setText( ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle").getString("Chart_Properties")); GridLayout layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; this.shell.setLayout(layout); Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + localizationResources.getString("Title") + " "); this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle()); item1.setControl(this.titleEditor); // build second tab TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + localizationResources.getString("Plot") + " "); this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot()); item2.setControl(this.plotEditor); // build the third tab TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + localizationResources.getString("Other") + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); }
From source file:com.rcp.wbw.demo.editor.SWTChartEditor.java
/** * Creates a new editor./*from w ww .java2 s . c o m*/ * * @param display * the display. * @param chart2edit * the chart to edit. */ public SWTChartEditor(Display display, JFreeChart chart2edit) { this.shell = new Shell(display, SWT.DIALOG_TRIM); this.shell.setSize(400, 500); this.chart = chart2edit; this.shell.setText(ResourceBundleWrapper.getBundle("org.jfree.chart.LocalizationBundle") .getString("Chart_Properties")); GridLayout layout = new GridLayout(2, true); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; this.shell.setLayout(layout); Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + localizationResources.getString("Title") + " "); this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle()); item1.setControl(this.titleEditor); // build second tab TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + localizationResources.getString("Plot") + " "); this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot()); item2.setControl(this.plotEditor); // build the third tab TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + localizationResources.getString("Other") + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); }