List of usage examples for org.eclipse.swt.widgets Button pack
public void pack()
From source file:org.eclipse.swt.snippets.Snippet247.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 247"); shell.setLayout(new RowLayout()); Text text = new Text(shell, SWT.MULTI | SWT.BORDER); String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command"; text.setText("Hit " + modifier + "+Return\nto see\nthe default button\nrun"); text.addTraverseListener(e -> {//from www . j av a 2 s. c om switch (e.detail) { case SWT.TRAVERSE_RETURN: if ((e.stateMask & SWT.MOD1) != 0) e.doit = true; } }); Button button = new Button(shell, SWT.PUSH); button.pack(); button.setText("OK"); button.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("OK selected"))); shell.setDefaultButton(button); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet126.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setLinesVisible(true);/*from w w w.j a va2 s .com*/ for (int i = 0; i < 3; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(100); } for (int i = 0; i < 12; i++) { new TableItem(table, SWT.NONE); } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { TableEditor editor = new TableEditor(table); CCombo combo = new CCombo(table, SWT.NONE); editor.grabHorizontal = true; editor.setEditor(combo, items[i], 0); editor = new TableEditor(table); Text text = new Text(table, SWT.NONE); editor.grabHorizontal = true; editor.setEditor(text, items[i], 1); editor = new TableEditor(table); Button button = new Button(table, SWT.CHECK); button.pack(); editor.minimumWidth = button.getSize().x; editor.horizontalAlignment = SWT.LEFT; editor.setEditor(button, items[i], 2); } 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 d = new Display(); Shell s = new Shell(d); s.setText("A Tabbed Shell Example"); final CoolBar bar = new CoolBar(s, SWT.BORDER); bar.setSize(280, 70);// w w w. j a va 2 s.c o m bar.setLocation(0, 0); // final Image openIcon = new Image(d, "c:\\icons\\open.jpg"); final CoolItem openCoolItem = new CoolItem(bar, SWT.NONE); final Button openBtn = new Button(bar, SWT.PUSH); // openBtn.setImage(openIcon); openBtn.pack(); Point size = openBtn.getSize(); openCoolItem.setControl(openBtn); openCoolItem.setSize(openCoolItem.computeSize(size.x, size.y)); s.open(); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:Snippet4.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Button b = new Button(shell, SWT.PUSH); b.setText("Open Dialog ..."); b.pack(); b.setLocation(10, 10);/*www.ja va 2s. com*/ b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent se) { Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); dialog.addListener(SWT.Traverse, new Listener() { public void handleEvent(Event e) { if (e.detail == SWT.TRAVERSE_ESCAPE) { e.doit = false; } } }); dialog.open(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet4.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 4"); Button b = new Button(shell, SWT.PUSH); b.setText("Open Dialog ..."); b.pack(); Rectangle clientArea = shell.getClientArea(); b.setLocation(clientArea.x + 10, clientArea.y + 10); b.addSelectionListener(widgetSelectedAdapter(e -> { Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); dialog.addListener(SWT.Traverse, t -> { if (t.detail == SWT.TRAVERSE_ESCAPE) { t.doit = false;/*from w w w.ja va 2 s . c o m*/ } }); dialog.open(); })); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet126.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 126"); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setLinesVisible(true);/*w w w .ja va 2s . co m*/ for (int i = 0; i < 3; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(100); } for (int i = 0; i < 12; i++) { new TableItem(table, SWT.NONE); } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { TableEditor editor = new TableEditor(table); CCombo combo = new CCombo(table, SWT.NONE); combo.setText("CCombo"); combo.add("item 1"); combo.add("item 2"); editor.grabHorizontal = true; editor.setEditor(combo, items[i], 0); editor = new TableEditor(table); Text text = new Text(table, SWT.NONE); text.setText("Text"); editor.grabHorizontal = true; editor.setEditor(text, items[i], 1); editor = new TableEditor(table); Button button = new Button(table, SWT.CHECK); button.pack(); editor.minimumWidth = button.getSize().x; editor.horizontalAlignment = SWT.LEFT; editor.setEditor(button, items[i], 2); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TableCellEditorComboTextButton.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setLinesVisible(true);//from w w w . j ava 2s .co m for (int i = 0; i < 3; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(100); } for (int i = 0; i < 12; i++) { new TableItem(table, SWT.NONE); } TableItem[] items = table.getItems(); for (int i = 0; i < items.length; i++) { TableEditor editor = new TableEditor(table); CCombo combo = new CCombo(table, SWT.NONE); combo.setText("CCombo"); combo.add("item 1"); combo.add("item 2"); editor.grabHorizontal = true; editor.setEditor(combo, items[i], 0); editor = new TableEditor(table); Text text = new Text(table, SWT.NONE); text.setText("Text"); editor.grabHorizontal = true; editor.setEditor(text, items[i], 1); editor = new TableEditor(table); Button button = new Button(table, SWT.CHECK); button.pack(); editor.minimumWidth = button.getSize().x; editor.horizontalAlignment = SWT.LEFT; editor.setEditor(button, items[i], 2); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet103.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 103"); shell.setBounds(10, 10, 200, 240);// w ww. j a v a 2s. c o m Table table = new Table(shell, SWT.NONE); Rectangle clientArea = shell.getClientArea(); table.setBounds(clientArea.x + 10, clientArea.y + 10, 160, 160); final TableItem[] items = new TableItem[4]; for (int i = 0; i < 4; i++) { new TableColumn(table, SWT.NONE).setWidth(40); } for (int i = 0; i < 4; i++) { items[i] = new TableItem(table, SWT.NONE); populateItem(items[i]); } Button button = new Button(shell, SWT.PUSH); button.setText("Change"); button.pack(); button.setLocation(10, 180); button.addListener(SWT.Selection, event -> { for (int i = 0; i < 4; i++) { populateItem(items[i]); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet95.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Widget"); final Table table = new Table(shell, SWT.MULTI); table.setLinesVisible(true);//w w w. j av a2 s.c o m table.setBounds(10, 10, 100, 100); for (int i = 0; i < 9; i++) { new TableItem(table, SWT.NONE).setText("item" + i); } Button button = new Button(shell, SWT.PUSH); button.setText("Capture"); button.pack(); button.setLocation(10, 140); button.addListener(SWT.Selection, event -> { Point tableSize = table.getSize(); GC gc = new GC(table); final Image image = new Image(display, tableSize.x, tableSize.y); gc.copyArea(image, 0, 0); gc.dispose(); Shell popup = new Shell(shell); popup.setText("Image"); popup.addListener(SWT.Close, e -> image.dispose()); Canvas canvas = new Canvas(popup, SWT.NONE); canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10); canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0)); popup.pack(); popup.open(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TableItemUpdateText.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 240);/*from ww w . j a v a 2s . c o m*/ Table table = new Table(shell, SWT.NONE); table.setBounds(10, 10, 160, 160); final TableItem[] items = new TableItem[4]; for (int i = 0; i < 4; i++) { new TableColumn(table, SWT.NONE).setWidth(40); } for (int i = 0; i < 4; i++) { items[i] = new TableItem(table, SWT.NONE); populateItem(items[i]); } Button button = new Button(shell, SWT.PUSH); button.setText("Change"); button.pack(); button.setLocation(10, 180); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { for (int i = 0; i < 4; i++) { populateItem(items[i]); } } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }