List of usage examples for org.eclipse.swt.widgets Button pack
public void pack()
From source file:org.eclipse.swt.snippets.Snippet68.java
public static void main(String[] args) { final Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setText("Snippet 68"); shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Stop Timer"); final Label label = new Label(shell, SWT.BORDER); label.setBackground(red);//w w w. j a v a 2 s .co m final int time = 500; final Runnable timer = new Runnable() { @Override public void run() { if (label.isDisposed()) return; Color color = label.getBackground().equals(red) ? blue : red; label.setBackground(color); display.timerExec(time, this); } }; display.timerExec(time, timer); button.addListener(SWT.Selection, event -> display.timerExec(-1, timer)); button.pack(); label.setLayoutData(new RowData(button.getSize())); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TimeStopWhenButtonPressing.java
public static void main(String[] args) { final Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Stop Timer"); final Label label = new Label(shell, SWT.BORDER); label.setBackground(red);/* w w w . j a v a 2s.c o m*/ final int time = 500; final Runnable timer = new Runnable() { public void run() { if (label.isDisposed()) return; Color color = label.getBackground().equals(red) ? blue : red; label.setBackground(color); display.timerExec(time, this); } }; display.timerExec(time, timer); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { display.timerExec(-1, timer); } }); button.pack(); label.setLayoutData(new RowData(button.getSize())); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CompViewer.java
public Ch3_Group(Composite parent) { super(parent, SWT.NONE); Group group = new Group(this, SWT.SHADOW_ETCHED_IN); group.setText("Group Label"); Label label = new Label(group, SWT.NONE); label.setText("Two buttons:"); label.setLocation(20, 20);/*from www . j a v a 2 s. c o m*/ label.pack(); Button button1 = new Button(group, SWT.PUSH); button1.setText("Push button"); button1.setLocation(20, 45); button1.pack(); Button button2 = new Button(group, SWT.CHECK); button2.setText("Check button"); button2.setBounds(20, 75, 90, 30); group.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 ww . j av a 2 s.c o m 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(); }
From source file:ummisco.gama.ui.views.displays.SWTChartEditor.java
/** * Creates a new editor.//from w w w .j ava 2s . c om * * @param display * the display. * @param chart2edit * the chart to edit. */ public SWTChartEditor(final Display display, final JFreeChart chart2edit, final Point position) { this.shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.NO_TRIM); this.shell.setSize(400, 500); this.shell.setBackground(WorkbenchHelper.getDisplay().getSystemColor(SWT.COLOR_BLACK)); // this.shell.setAlpha(140); this.chart = chart2edit; this.shell.setText("Chart properties"); this.shell.setLocation(position); final GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; this.shell.setLayout(layout); final Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); final TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab final TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + "Title" + " "); this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle()); item1.setControl(this.titleEditor); // build second tab final TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + "Plot" + " "); this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot()); item2.setControl(this.plotEditor); // build the third tab final TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + "Other" + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons final Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); cancel.pack(); cancel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); final Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); ok.pack(); ok.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); }
From source file:msi.gama.gui.swt.controls.SWTChartEditor.java
/** * Creates a new editor./*ww w. ja va 2 s . c o m*/ * * @param display the display. * @param chart2edit the chart to edit. */ public SWTChartEditor(final Display display, final JFreeChart chart2edit, final Point position) { this.shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.NO_TRIM); this.shell.setSize(400, 500); this.shell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); // this.shell.setAlpha(140); this.chart = chart2edit; this.shell.setText("Chart properties"); this.shell.setLocation(position); GridLayout layout = new GridLayout(2, false); 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(" " + "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(" " + "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(" " + "Other" + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); cancel.pack(); cancel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); ok.pack(); ok.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); }