List of usage examples for org.eclipse.swt.widgets Button Button
public Button(Composite parent, int style)
From source file:FocusTraversal.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setLayout(new RowLayout()); composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); Button button1 = new Button(composite1, SWT.PUSH); button1.setText("Button1"); Button button3 = new Button(composite1, SWT.PUSH); button3.setText("Button3"); Button radioButton1 = new Button(composite1, SWT.RADIO); radioButton1.setText("radio-1"); Button radioButton2 = new Button(composite1, SWT.RADIO); radioButton2.setText("radio-2"); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new RowLayout()); composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); Button button2 = new Button(composite2, SWT.PUSH); button2.setText("Button2"); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0);//from www . j av a2s. com composite1.setTabList(new Control[] { button1, button3 }); composite2.setTabList(new Control[] { button2, combo }); shell.setTabList(new Control[] { composite2, composite1 }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:ClipBoardCopyPaster.java
public static void main(String[] args) { Display display = new Display(); final Clipboard cb = new Clipboard(display); final Shell shell = new Shell(display); final Text text = new Text(shell, SWT.BORDER | SWT.SINGLE); text.setBounds(5, 5, 100, 20);//from w w w.j a v a 2 s . c om Button copy = new Button(shell, SWT.PUSH); copy.setBounds(5, 50, 100, 20); copy.setText("Copy"); copy.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String textData = text.getSelectionText(); if (textData.length() > 0) { TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer }); } } }); Button paste = new Button(shell, SWT.PUSH); paste.setBounds(5, 90, 100, 20); paste.setText("Paste"); paste.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { TextTransfer transfer = TextTransfer.getInstance(); String data = (String) cb.getContents(transfer); if (data != null) { text.insert(data); } } }); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cb.dispose(); display.dispose(); }
From source file:Snippet172.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(4, false); shell.setLayout(layout);/*from w w w . j ava 2s.c om*/ Button b = new Button(shell, SWT.PUSH); b.setText("LEFT, TOP"); b.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("LEFT, CENTER"); b.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("LEFT, BOTTOM"); b.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("LEFT, FILL"); b.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("CENTER, TOP"); b.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("CENTER, CENTER"); b.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("CENTER, BOTTOM"); b.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("CENTER, FILL"); b.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("RIGHT, TOP"); b.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("RIGHT, CENTER"); b.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("RIGHT, BOTTOM"); b.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("RIGHT, FILL"); b.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("FILL, TOP"); b.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("FILL, CENTER"); b.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("FILL, BOTTOM"); b.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, true, 1, 1)); b = new Button(shell, SWT.PUSH); b.setText("FILL, FILL"); b.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutHORIZONTALALIGNCENTER.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); GridLayout layout = new GridLayout(); layout.numColumns = 3;/*from w ww .ja v a 2 s. 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); // Create button "three" data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); Button three = new Button(composite, SWT.PUSH); three.setText("three"); three.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet20.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); CoolBar bar = new CoolBar(shell, SWT.BORDER); for (int i = 0; i < 2; i++) { CoolItem item = new CoolItem(bar, SWT.NONE); Button button = new Button(bar, SWT.PUSH); button.setText("Button " + i); Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); item.setPreferredSize(item.computeSize(size.x, size.y)); item.setControl(button);// www . j av a2 s . c o m } bar.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TabItemWithToolTipImage.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")); Button button = new Button(tabFolder, SWT.PUSH); button.setText("Page " + i); item.setControl(button);//w w w . j ava 2 s.c o m } tabFolder.pack(); 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 ww w . j av a 2 s .c om*/ 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) { ColorDialog cd = new ColorDialog(s); cd.setText("ColorDialog Demo"); cd.setRGB(new RGB(255, 255, 255)); RGB newColor = cd.open(); if (newColor == null) { return; } t.setBackground(new Color(d, newColor)); } }); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:ScrollCompisiteHoriVertical.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SashForm Test"); shell.setLayout(new FillLayout()); // Create the ScrolledComposite to scroll horizontally and vertically ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); child.setSize(400, 400);//from w w w . j av a 2 s. c o m sc.setContent(child); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ScrolledCompositeMiniSize.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("SashForm Test"); shell.setLayout(new FillLayout()); // Create the ScrolledComposite to scroll horizontally and vertically ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite child = new Composite(sc, SWT.NONE); child.setLayout(new FillLayout()); new Button(child, SWT.PUSH).setText("One"); new Button(child, SWT.PUSH).setText("Two"); sc.setMinSize(400, 400);/*w w w . j a va2 s. c om*/ // Expand both horizontally and vertically sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setContent(child); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:SWTGridLayout.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setSize(300, 200);//from w ww .j ava2 s . c o m shell.setLayout(new RowLayout()); final Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 4; composite.setLayout(gridLayout); for (int loopIndex = 0; loopIndex < 18; loopIndex++) { Button button = new Button(composite, SWT.PUSH); button.setText("Button " + loopIndex); } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }