List of usage examples for org.eclipse.swt.widgets Button setLayoutData
public void setLayoutData(Object layoutData)
From source file:FormLayoutControlOffsetAttachment.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"); Point size = button1.computeSize(SWT.DEFAULT, SWT.DEFAULT); int offset = size.x / 2; FormData formData = new FormData(); formData.left = new FormAttachment(50, -1 * offset); button1.setLayoutData(formData); shell.setSize(450, 400);// w w w . j av a2s . co m shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutFormAttachmentSetButton.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. j a v a2 s .co m*/ layout.marginWidth = 10; shell.setLayout(layout); Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutAttachFourSidesControl.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"); FormData formData = new FormData(); formData.left = new FormAttachment(50); formData.right = new FormAttachment(100); formData.top = new FormAttachment(50); formData.bottom = new FormAttachment(100); button1.setLayoutData(formData); shell.setSize(450, 400);//from w ww .jav a2s . c om shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet282.java
public static void main(String[] args) { final Display display = new Display(); final Clipboard clipboard = new Clipboard(display); final Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setText("Snippet 282"); shell.setLayout(new GridLayout()); shell.setText("Clipboard ImageTransfer"); final Button imageButton = new Button(shell, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.minimumHeight = 400;// w w w . ja v a 2 s .c o m gd.minimumWidth = 600; imageButton.setLayoutData(gd); final Text imageText = new Text(shell, SWT.BORDER); imageText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); Composite buttons = new Composite(shell, SWT.NONE); buttons.setLayout(new GridLayout(4, true)); Button button = new Button(buttons, SWT.PUSH); button.setText("Open"); button.addListener(SWT.Selection, event -> { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { imageButton.setText(""); Image image = imageButton.getImage(); if (image != null) image.dispose(); image = new Image(display, string); imageButton.setImage(image); imageText.setText(string); } }); button = new Button(buttons, SWT.PUSH); button.setText("Copy"); button.addListener(SWT.Selection, event -> { Image image = imageButton.getImage(); if (image != null) { ImageTransfer imageTransfer = ImageTransfer.getInstance(); TextTransfer textTransfer = TextTransfer.getInstance(); clipboard.setContents(new Object[] { image.getImageData(), imageText.getText() }, new Transfer[] { imageTransfer, textTransfer }); } }); button = new Button(buttons, SWT.PUSH); button.setText("Paste"); button.addListener(SWT.Selection, event -> { ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance()); if (imageData != null) { imageButton.setText(""); Image image = imageButton.getImage(); if (image != null) image.dispose(); image = new Image(display, imageData); imageButton.setImage(image); } else { imageButton.setText("No image"); imageButton.setImage(null); } String text = (String) clipboard.getContents(TextTransfer.getInstance()); if (text != null) { imageText.setText(text); } else { imageText.setText(""); } }); button = new Button(buttons, SWT.PUSH); button.setText("Clear"); button.addListener(SWT.Selection, event -> { imageButton.setText(""); Image image = imageButton.getImage(); if (image != null) image.dispose(); imageButton.setImage(null); imageText.setText(""); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutSimpleDmo.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(4, false); gridLayout.verticalSpacing = 8;/*from w ww . j a v a 2s. c o m*/ shell.setLayout(gridLayout); Label label = new Label(shell, SWT.NULL); label.setText("Title: "); Text title = new Text(shell, SWT.SINGLE | SWT.BORDER); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; title.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Author(s): "); Text authors = new Text(shell, SWT.SINGLE | SWT.BORDER); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; authors.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Cover: "); gridData = new GridData(); gridData.verticalSpan = 3; label.setLayoutData(gridData); CLabel cover = new CLabel(shell, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 1; gridData.verticalSpan = 3; gridData.heightHint = 100; gridData.widthHint = 100; cover.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Pages"); Text pages = new Text(shell, SWT.SINGLE | SWT.BORDER); pages.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); label = new Label(shell, SWT.NULL); label.setText("Publisher"); Text publisher = new Text(shell, SWT.SINGLE | SWT.BORDER); publisher.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); label = new Label(shell, SWT.NULL); label.setText("Rating"); Combo rating = new Combo(shell, SWT.READ_ONLY); rating.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); rating.add("5"); rating.add("4"); rating.add("3"); rating.add("2"); rating.add("1"); label = new Label(shell, SWT.NULL); label.setText("Abstract:"); Text bookAbstract = new Text(shell, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); gridData.horizontalSpan = 3; gridData.grabExcessVerticalSpace = true; bookAbstract.setLayoutData(gridData); Button enter = new Button(shell, SWT.PUSH); enter.setText("Enter"); gridData = new GridData(); gridData.horizontalSpan = 4; gridData.horizontalAlignment = GridData.END; enter.setLayoutData(gridData); title.setText("Professional Java Interfaces with SWT/JFace"); authors.setText("Jack Li Guojie"); pages.setText("500pp"); publisher.setText("John Wiley & Sons"); cover.setBackground(new Image(display, "yourFile.gif")); bookAbstract.setText("SWT/JFace. "); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);//from ww w. j a va 2s .c o m Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 20; gridLayout.marginWidth = 20; 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_HORIZONTAL); three.setLayoutData(gridData); Button four = new Button(composite, SWT.PUSH); four.setText("four"); gridData = new GridData(GridData.FILL_BOTH); four.setLayoutData(gridData); data = new FormData(); data.top = new FormAttachment(0, 15); data.left = new FormAttachment(one, 25); data.bottom = new FormAttachment(50, -15); data.right = new FormAttachment(100, -25); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutComplex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);/*from ww w.j a va 2s. c o m*/ Button one = new Button(shell, SWT.PUSH); one.setText("One"); FormData data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(50, -5); one.setLayoutData(data); Composite composite = new Composite(shell, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.marginHeight = 0; 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); data = new FormData(); data.top = new FormAttachment(0, 5); data.left = new FormAttachment(one, 5); data.bottom = new FormAttachment(50, -5); data.right = new FormAttachment(100, -5); composite.setLayoutData(data); Button five = new Button(shell, SWT.PUSH); five.setText("five"); data = new FormData(); data.top = new FormAttachment(one, 5); data.left = new FormAttachment(0, 5); data.bottom = new FormAttachment(100, -5); data.right = new FormAttachment(100, -5); five.setLayoutData(data); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet295.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Shell"); FillLayout fillLayout = new FillLayout(); fillLayout.marginWidth = 10;/*from w w w . j av a 2s.com*/ fillLayout.marginHeight = 10; shell.setLayout(fillLayout); Button open = new Button(shell, SWT.PUSH); open.setText("Prompt for a String"); open.addSelectionListener(widgetSelectedAdapter(e -> { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText("Dialog Shell"); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = 10; formLayout.marginHeight = 10; formLayout.spacing = 10; dialog.setLayout(formLayout); Label label = new Label(dialog, SWT.NONE); label.setText("Type a String:"); FormData data = new FormData(); label.setLayoutData(data); Button cancel = new Button(dialog, SWT.PUSH); cancel.setText("Cancel"); data = new FormData(); data.width = 60; data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); cancel.setLayoutData(data); cancel.addSelectionListener(widgetSelectedAdapter(event -> { System.out.println("User cancelled dialog"); dialog.close(); })); final Text text = new Text(dialog, SWT.BORDER); data = new FormData(); data.width = 200; data.left = new FormAttachment(label, 0, SWT.DEFAULT); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(label, 0, SWT.CENTER); data.bottom = new FormAttachment(cancel, 0, SWT.DEFAULT); text.setLayoutData(data); Button ok = new Button(dialog, SWT.PUSH); ok.setText("OK"); data = new FormData(); data.width = 60; data.right = new FormAttachment(cancel, 0, SWT.DEFAULT); data.bottom = new FormAttachment(100, 0); ok.setLayoutData(data); ok.addSelectionListener(widgetSelectedAdapter(event -> { System.out.println("User typed: " + text.getText()); dialog.close(); })); dialog.setDefaultButton(ok); dialog.pack(); dialog.open(); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutGrabExcess.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;//from ww w .j av a 2 s . c om gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); // Default alignment List list = new List(shell, SWT.BORDER); list.add("item 1"); list.add("item 2"); list.add("item 3"); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; list.setLayoutData(gridData); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); GridData gridData2 = new GridData(); gridData2.grabExcessVerticalSpace = true; gridData2.grabExcessHorizontalSpace = true; gridData2.verticalAlignment = GridData.FILL; gridData2.horizontalAlignment = GridData.FILL; button2.setLayoutData(gridData2); Button button3 = new Button(shell, SWT.PUSH); button3.setText("3"); shell.setSize(450, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:Snippet71.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.pack();/* w w w. ja va 2 s .c o m*/ shell.open(); Shell dialog = new Shell(shell, SWT.DIALOG_TRIM); Label label = new Label(dialog, SWT.NONE); label.setText("Exit the application?"); Button okButton = new Button(dialog, SWT.PUSH); okButton.setText("&OK"); Button cancelButton = new Button(dialog, SWT.PUSH); cancelButton.setText("&Cancel"); FormLayout form = new FormLayout(); form.marginWidth = form.marginHeight = 8; dialog.setLayout(form); FormData okData = new FormData(); okData.top = new FormAttachment(label, 8); okButton.setLayoutData(okData); FormData cancelData = new FormData(); cancelData.left = new FormAttachment(okButton, 8); cancelData.top = new FormAttachment(okButton, 0, SWT.TOP); cancelButton.setLayoutData(cancelData); dialog.setDefaultButton(okButton); dialog.pack(); dialog.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }