List of usage examples for org.eclipse.swt.widgets Button setLayoutData
public void setLayoutData(Object layoutData)
From source file:org.eclipse.swt.snippets.Snippet51.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 51"); shell.setBounds(10, 10, 300, 300);// w w w .j ava2 s.co m shell.setLayout(new GridLayout(2, true)); final Table table = new Table(shell, SWT.NONE); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; table.setLayoutData(data); for (int i = 0; i < 99; i++) { new TableItem(table, SWT.NONE).setText("item " + i); } Button upButton = new Button(shell, SWT.PUSH); upButton.setText("Scroll up one page"); upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); upButton.addListener(SWT.Selection, event -> { int height = table.getClientArea().height; int visibleItemCount = height / table.getItemHeight(); int topIndex = table.getTopIndex(); int newTopIndex = Math.max(0, topIndex - visibleItemCount); if (topIndex != newTopIndex) { table.setTopIndex(newTopIndex); } }); Button downButton = new Button(shell, SWT.PUSH); downButton.setText("Scroll down one page"); downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); downButton.addListener(SWT.Selection, event -> { int height = table.getClientArea().height; int visibleItemCount = height / table.getItemHeight(); int topIndex = table.getTopIndex(); int newTopIndex = Math.min(table.getItemCount(), topIndex + visibleItemCount); if (topIndex != newTopIndex) { table.setTopIndex(newTopIndex); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } 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 www . ja v a 2 s . 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:FormLayoutFormData.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); layout.marginHeight = 5;//from w w w. ja v a 2s .com layout.marginWidth = 10; shell.setLayout(layout); Button button = new Button(shell, SWT.PUSH); button.setText("Button"); FormData data = new FormData(); data.height = 50; data.width = 50; button.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet172.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 172"); GridLayout layout = new GridLayout(4, false); shell.setLayout(layout);/*from w w w . ja v a 2s . c o m*/ 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: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 . j av a2s .c o m*/ 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(); }
From source file:org.eclipse.swt.snippets.Snippet266.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 266"); shell.setLayout(new GridLayout(2, true)); TabFolder tabFolder = new TabFolder(shell, SWT.NONE); tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("Widget"); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new GridLayout()); Tree tree = new Tree(composite, SWT.BORDER); item.setControl(composite);/*from ww w . j a v a 2 s.co m*/ tree.setHeaderVisible(true); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TreeColumn column1 = new TreeColumn(tree, SWT.NONE); column1.setText("Standard"); TreeColumn column2 = new TreeColumn(tree, SWT.NONE); column2.setText("Widget"); TreeItem branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Efficient", "Portable" }); TreeItem leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch.setExpanded(true); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Native", "Controls" }); leaf = new TreeItem(branch, SWT.NONE); leaf.setText(new String[] { "Cross", "Platform" }); branch = new TreeItem(tree, SWT.NONE); branch.setText(new String[] { "Cross", "Platform" }); column1.pack(); column2.pack(); item = new TabItem(tabFolder, SWT.NONE); item.setText("Toolkit"); Button button = new Button(shell, SWT.CHECK); button.setText("Totally"); button.setSelection(true); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); button = new Button(shell, SWT.PUSH); button.setText("Awesome"); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FormLayoutAttachAnotherControl.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button2"); FormData formData = new FormData(); formData.left = new FormAttachment(button1); button2.setLayoutData(formData); Button button3 = new Button(shell, SWT.PUSH); button3.setText("button3"); formData = new FormData(); formData.top = new FormAttachment(button2, 10); button3.setLayoutData(formData);/*from ww w . jav a2 s .com*/ shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutAnotherControl.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button2"); FormData formData = new FormData(); formData.left = new FormAttachment(button1); button2.setLayoutData(formData); Button button3 = new Button(shell, SWT.PUSH); button3.setText("button3"); formData = new FormData(); formData.top = new FormAttachment(button2, 10); formData.left = new FormAttachment(button2, 0, SWT.LEFT); button3.setLayoutData(formData);/*from www . j ava 2 s.c o m*/ shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet363.java
public static void main(String[] args) { Display display = new Display(); errorIcon = display.getSystemImage(SWT.ICON_ERROR); Shell shell = new Shell(display); shell.setText("Snippet 363"); shell.setLayout(new GridLayout(2, false)); shell.setText("LiveRegion Test"); icon = new Label(shell, SWT.NONE); icon.setLayoutData(new GridData(32, 32)); liveLabel = new Text(shell, SWT.READ_ONLY); GC gc = new GC(liveLabel); Point pt = gc.textExtent(errorMessage); GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); data.minimumWidth = (int) (pt.x + gc.getFontMetrics().getAverageCharacterWidth() * 2); gc.dispose();/*from ww w . java 2 s .com*/ liveLabel.setLayoutData(data); liveLabel.setText(""); liveLabel.getAccessible().addAccessibleAttributeListener(new AccessibleAttributeAdapter() { @Override public void getAttributes(AccessibleAttributeEvent e) { e.attributes = new String[] { "container-live", "polite", "live", "polite", "container-live-role", "status", }; } }); final Label textFieldLabel = new Label(shell, SWT.NONE); textFieldLabel.setText("Type a number:"); textFieldLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER); textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); final Button okButton = new Button(shell, SWT.PUSH); okButton.setText("OK"); okButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1)); okButton.setEnabled(false); textField.addModifyListener(e -> { boolean isNumber = false; String textValue = textField.getText(); try { Integer.parseInt(textValue); isNumber = true; setMessageText(false, "Thank-you"); } catch (NumberFormatException ex) { if (textValue.isEmpty()) { setMessageText(false, ""); } else { setMessageText(true, "Error: Number expected."); } } okButton.setEnabled(isNumber); }); textField.setFocus(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FormLayoutCenterAnotherControl.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button222222222222222222222"); FormData formData = new FormData(); formData.left = new FormAttachment(button1); button2.setLayoutData(formData); Button button3 = new Button(shell, SWT.PUSH); button3.setText("button3"); formData = new FormData(); formData.top = new FormAttachment(button2, 10); formData.left = new FormAttachment(button2, 0, SWT.CENTER); button3.setLayoutData(formData);/*from w ww. j a v a 2s . co m*/ shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }