List of usage examples for org.eclipse.swt.widgets Button setLayoutData
public void setLayoutData(Object layoutData)
From source file:org.eclipse.swt.snippets.Snippet212.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 212"); shell.setLayout(new GridLayout()); styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); styledText.setText(text);/*from w w w . j av a 2 s . c om*/ int offset = text.indexOf("\uFFFC", 0); addImage(display.getSystemImage(SWT.ICON_QUESTION), offset); offset = text.indexOf("\uFFFC", offset + 1); addImage(display.getSystemImage(SWT.ICON_INFORMATION), offset); // use a verify listener to dispose the images styledText.addVerifyListener(event -> { if (event.start == event.end) return; String text = styledText.getText(event.start, event.end - 1); int index = text.indexOf('\uFFFC'); while (index != -1) { StyleRange style = styledText.getStyleRangeAtOffset(event.start + index); if (style != null) { Image image = (Image) style.data; if (image != null) image.dispose(); } index = text.indexOf('\uFFFC', index + 1); } }); // draw images on paint event styledText.addPaintObjectListener(event -> { StyleRange style = event.style; Image image = (Image) style.data; if (!image.isDisposed()) { int x = event.x; int y = event.y + event.ascent - style.metrics.ascent; event.gc.drawImage(image, x, y); } }); styledText.addListener(SWT.Dispose, event -> { StyleRange[] styles = styledText.getStyleRanges(); for (int i = 0; i < styles.length; i++) { StyleRange style = styles[i]; if (style.data != null) { Image image = (Image) style.data; if (image != null) image.dispose(); } } }); Button button = new Button(shell, SWT.PUSH); button.setText("Add Image"); button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); button.addListener(SWT.Selection, event -> { FileDialog dialog = new FileDialog(shell); String filename = dialog.open(); if (filename != null) { try { Image image = new Image(display, filename); int offset1 = styledText.getCaretOffset(); styledText.replaceTextRange(offset1, 0, "\uFFFC"); addImage(image, offset1); } catch (Exception e) { e.printStackTrace(); } } }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:FormLayoutLeftRight.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); FormData formData = new FormData(); formData.left = new FormAttachment(20); formData.top = new FormAttachment(20); button1.setLayoutData(formData); shell.pack();//from w w w . j a v a 2 s .c o m shell.open(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet375.java
public static void main(String[] args) throws Exception { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 375"); shell.setLayout(new GridLayout(1, false)); final StringBuilder sb = new StringBuilder(); final Random random = new Random(2546); for (int i = 0; i < 200; i++) { sb.append("Very very long text about ").append(random.nextInt(2000)).append("\t"); if (i % 10 == 0) { sb.append("\n"); }/*from w ww . j a v a2 s. c o m*/ } // H SCROLL final Label lbl1 = new Label(shell, SWT.NONE); lbl1.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl1.setText("Horizontal Scroll"); final StyledText txt1 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL); txt1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt1.setText(sb.toString()); txt1.setMouseNavigatorEnabled(true); // V_SCROLL final Label lbl2 = new Label(shell, SWT.NONE); lbl2.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl2.setText("Vertical Scroll"); final StyledText txt2 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); txt2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt2.setText(sb.toString()); txt2.setMouseNavigatorEnabled(true); // H SCROLL & V_SCROLL final Label lbl3 = new Label(shell, SWT.NONE); lbl3.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl3.setText("Horizontal and Vertical Scroll"); final StyledText txt3 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); txt3.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); txt3.setText(sb.toString()); txt3.setMouseNavigatorEnabled(true); final Button enableDisableButton = new Button(shell, SWT.PUSH); enableDisableButton.setLayoutData(new GridData(GridData.END, GridData.FILL, true, false)); enableDisableButton.setText("Disable Mouse Navigation"); enableDisableButton.addListener(SWT.Selection, e -> { if (txt3.getMouseNavigatorEnabled()) { enableDisableButton.setText("Enable Mouse Navigation"); } else { enableDisableButton.setText("Disable Mouse Navigation"); } txt3.setMouseNavigatorEnabled(!txt3.getMouseNavigatorEnabled()); }); // Disabled Scroll at start final Label lbl4 = new Label(shell, SWT.NONE); lbl4.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl4.setText("No scroll at start"); final StyledText txt4 = new StyledText(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); final GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true); gd.minimumHeight = 100; txt4.setLayoutData(gd); txt4.setText("Disabled scroll"); txt4.setMouseNavigatorEnabled(true); // Disabled Scroll final Label lbl5 = new Label(shell, SWT.NONE); lbl5.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); lbl5.setText("No scroll"); final StyledText txt5 = new StyledText(shell, SWT.MULTI | SWT.BORDER); final GridData gd5 = new GridData(GridData.FILL, GridData.FILL, true, true); gd5.minimumHeight = 100; txt5.setLayoutData(gd5); txt5.setText("No scroll"); txt5.setMouseNavigatorEnabled(true); shell.setSize(800, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:YetAnotherBorderLayout.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new YetAnotherBorderLayout()); Button b1 = new Button(shell, SWT.PUSH); b1.setText("North"); b1.setLayoutData(BorderData.NORTH); Button b2 = new Button(shell, SWT.PUSH); b2.setText("South"); b2.setLayoutData(BorderData.SOUTH);/*from w w w. j a va2 s .c o m*/ Button b3 = new Button(shell, SWT.PUSH); b3.setText("East"); b3.setLayoutData(BorderData.EAST); Button b4 = new Button(shell, SWT.PUSH); b4.setText("West"); b4.setLayoutData(BorderData.WEST); Button b5 = new Button(shell, SWT.PUSH); b5.setText("Center"); b5.setLayoutData(BorderData.CENTER); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:FormLayoutAttachEachOther.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new FormLayout()); Button button1 = new Button(shell, SWT.PUSH); button1.setText("button1"); FormData formData = new FormData(); formData.left = new FormAttachment(20); formData.top = new FormAttachment(20); button1.setLayoutData(formData); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button number 2"); formData = new FormData(); formData.left = new FormAttachment(button1, 0, SWT.CENTER); formData.top = new FormAttachment(button1, 0, SWT.CENTER); button2.setLayoutData(formData);/* ww w . j a va 2s . co m*/ shell.pack(); shell.open(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:GridLayoutGrabExcessVertical.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;/* w ww . j a va 2 s. c o m*/ 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.horizontalAlignment = GridData.FILL; list.setLayoutData(gridData); Button button2 = new Button(shell, SWT.PUSH); button2.setText("button #2"); GridData gridData2 = new GridData(); gridData2.grabExcessVerticalSpace = true; gridData2.verticalAlignment = 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:BorderLayoutSWT.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new BorderLayout()); Button buttonWest = new Button(shell, SWT.PUSH); buttonWest.setText("West"); buttonWest.setLayoutData(new BorderLayout.BorderData(BorderLayout.WEST)); Button buttonEast = new Button(shell, SWT.PUSH); buttonEast.setText("East"); buttonEast.setLayoutData(new BorderLayout.BorderData(BorderLayout.EAST)); Button buttonNorth = new Button(shell, SWT.PUSH); buttonNorth.setText("North"); buttonNorth.setLayoutData(new BorderLayout.BorderData(BorderLayout.NORTH)); Button buttonSouth = new Button(shell, SWT.PUSH); buttonSouth.setText("South"); buttonSouth.setLayoutData(new BorderLayout.BorderData(BorderLayout.SOUTH)); Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); text.setText("Center"); text.setLayoutData(new BorderLayout.BorderData(BorderLayout.CENTER)); shell.pack();/* www .j a va 2s .c o m*/ shell.open(); // textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet313.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 313"); shell.setLayout(new FormLayout()); final Button button = new Button(shell, SWT.PUSH); button.setText(">>"); FormData data = new FormData(); data.top = new FormAttachment(0, 4); data.right = new FormAttachment(100, -4); button.setLayoutData(data); final Composite composite = new Composite(shell, SWT.BORDER); final FormData down = new FormData(); down.top = new FormAttachment(button, 4, SWT.BOTTOM); down.bottom = new FormAttachment(100, -4); down.left = new FormAttachment(0, 4); down.right = new FormAttachment(100, -4); final FormData up = new FormData(); up.top = new FormAttachment(0); up.bottom = new FormAttachment(0); up.left = new FormAttachment(0); up.right = new FormAttachment(0); composite.setLayoutData(up);/*w ww. ja va 2s. c om*/ button.addSelectionListener(widgetSelectedAdapter(e -> { if (composite.getLayoutData() == up) { composite.setLayoutData(down); button.setText("<<"); } else { composite.setLayoutData(up); button.setText(">>"); } shell.pack(); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet175.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 175"); shell.setLayout(new GridLayout(3, false)); Button b = new Button(shell, SWT.PUSH); b.setText("Button 0"); final Button bHidden = new Button(shell, SWT.PUSH); bHidden.setText("Button 1"); GridData data = new GridData(); data.exclude = true;/* w w w . j av a 2s . c om*/ data.horizontalSpan = 2; data.horizontalAlignment = SWT.FILL; bHidden.setLayoutData(data); 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("Button 4"); b = new Button(shell, SWT.CHECK); b.setText("hide"); b.setSelection(true); b.addListener(SWT.Selection, e -> { Button b1 = (Button) e.widget; GridData data1 = (GridData) bHidden.getLayoutData(); data1.exclude = b1.getSelection(); bHidden.setVisible(!data1.exclude); shell.layout(false); }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutWidgetExclude.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout(3, false)); Button b = new Button(shell, SWT.PUSH); b.setText("Button 0"); final Button bHidden = new Button(shell, SWT.PUSH); bHidden.setText("Button 1"); GridData data = new GridData(); data.exclude = true;/*w ww . j ava2 s . c om*/ data.horizontalSpan = 2; data.horizontalAlignment = SWT.FILL; bHidden.setLayoutData(data); 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("Button 4"); b = new Button(shell, SWT.CHECK); b.setText("hide"); b.setSelection(true); b.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { Button b = (Button) e.widget; GridData data = (GridData) bHidden.getLayoutData(); data.exclude = b.getSelection(); bHidden.setVisible(!data.exclude); shell.layout(false); } }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }