List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:Snippet177.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); RowLayout layout = new RowLayout(SWT.VERTICAL); layout.wrap = true;// w w w.j av a 2 s . c o m layout.fill = true; layout.justify = false; shell.setLayout(layout); Button b = new Button(shell, SWT.PUSH); b.setText("Button 1"); b = new Button(shell, SWT.PUSH); b.setText("Button 2"); b = new Button(shell, SWT.PUSH); b.setText("Button 3"); b = new Button(shell, SWT.PUSH); b.setText("Not shown"); b.setVisible(false); RowData data = new RowData(); data.exclude = true; b.setLayoutData(data); b = new Button(shell, SWT.PUSH); b.setText("Button 200 high"); data = new RowData(); data.height = 200; b.setLayoutData(data); b = new Button(shell, SWT.PUSH); b.setText("Button 200 wide"); data = new RowData(); data.width = 200; b.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;// w ww .ja va 2s .co m 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); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; composite.setLayoutData(data); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 15; composite.setLayout(layout); // Create button "two" data = new GridData(GridData.FILL_BOTH); Button two = new Button(composite, SWT.PUSH); two.setText("two"); two.setLayoutData(data); // Create button "three" data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); Button three = new Button(composite, SWT.PUSH); three.setText("three"); three.setLayoutData(data); // Create button "four" data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); Button four = new Button(composite, SWT.PUSH); four.setText("four"); four.setLayoutData(data); // Create the long button across the bottom data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; data.horizontalSpan = 3; data.heightHint = 150; Button five = new Button(shell, SWT.PUSH); five.setText("five"); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { Display display = new Display(); // Create the main window final Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); Font font = null;/*from w w w.ja va 2 s .com*/ Color color = null; if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:BusyIndicatorDemo.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("BusyIndicator Test"); shell.setLayout(new FillLayout()); final Button button = new Button(shell, SWT.PUSH); button.setText(RUN);/*from w w w. ja v a2s .c om*/ button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Change the button's text button.setText(IS_RUNNING); // Show the busy indicator BusyIndicator.showWhile(button.getDisplay(), new SleepThread(SLEEP_TIME)); // Thread has completed; reset the button's text button.setText(RUN); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet108.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Label label = new Label(shell, SWT.NONE); label.setText("Enter your name:"); Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new RowData(100, SWT.DEFAULT)); Button ok = new Button(shell, SWT.PUSH); ok.setText("Ok"); Button cancel = new Button(shell, SWT.PUSH); cancel.setText("Cancel"); shell.setDefaultButton(cancel);/*from w ww .j ava2 s .c o m*/ shell.setLayout(new RowLayout()); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ColorDialogButtonActionSetLabelBackground.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Color Chooser"); shell.setLayout(new GridLayout(2, false)); final Label colorLabel = new Label(shell, SWT.NONE); colorLabel.setText("Color"); Button button = new Button(shell, SWT.PUSH); button.setText("Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Color color = new Color(shell.getDisplay(), new RGB(0, 255, 0)); ColorDialog dlg = new ColorDialog(shell); dlg.setRGB(colorLabel.getBackground().getRGB()); dlg.setText("Choose a Color"); RGB rgb = dlg.open();//from www . j av a 2s .c o m if (rgb != null) { color.dispose(); color = new Color(shell.getDisplay(), rgb); colorLabel.setBackground(color); color.dispose(); } } }); shell.pack(); 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 d = new Display(); final Shell s = new Shell(d); s.setSize(300, 300);//from w ww . ja va 2s. c om s.setText("A FontDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Font"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:MainClass.java
public static void main(String[] a) { final Display d = new Display(); final Shell s = new Shell(d); s.setSize(300, 300);/* w w w.j a va2 s. com*/ s.setText("A ColorDialog Example"); s.setLayout(new FillLayout(SWT.VERTICAL)); final Text t = new Text(s, SWT.BORDER | SWT.MULTI); final Button b = new Button(s, SWT.PUSH | SWT.BORDER); b.setText("Change Color"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FontDialog fd = new FontDialog(s, SWT.NONE); fd.setText("Select Font"); fd.setRGB(new RGB(0, 0, 255)); FontData defaultFont = new FontData("Courier", 10, SWT.BOLD); fd.setFontData(defaultFont); FontData newFont = fd.open(); if (newFont == null) return; t.setFont(new Font(d, newFont)); t.setForeground(new Color(d, fd.getRGB())); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:FontDialogColorFontData.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Font Chooser"); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Font font = null;/*from w ww .j a va2 s . co m*/ Color color = null; FontDialog dlg = new FontDialog(shell); if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); if (font != null) font.dispose(); if (color != null) color.dispose(); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutComposite.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FormLayout()); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0;//from w ww . ja va2 s . com gridLayout.marginWidth = 0; composite.setLayout(gridLayout); Button two = new Button(composite, SWT.PUSH); two.setText("two"); GridData gridData = new GridData(GridData.FILL_BOTH); two.setLayoutData(gridData); Button three = new Button(composite, SWT.PUSH); three.setText("three"); gridData = new GridData(GridData.FILL_BOTH); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); Button five = new Button(shell, SWT.PUSH); five.setText("five"); FormData data = new FormData(); data.top = new FormAttachment(two, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(two, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(100, -5); composite.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }