List of usage examples for org.eclipse.swt.widgets Label setLayoutData
public void setLayoutData(Object layoutData)
From source file:HorizontalSeparatorLabelExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(); shell.setLayout(new GridLayout(1, false)); // Create a horizontal separator Label separator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); shell.open();/*ww w . j a v a 2s .c o m*/ while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:ComboSelectedIndex.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Show Message Box"); shell.setLayout(new GridLayout(2, false)); new Label(shell, SWT.NONE).setText("Icon:"); final Combo icons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); icons.add("A"); icons.add("B"); icons.add("C"); icons.select(0);/*from w ww . ja v a 2 s . co m*/ new Label(shell, SWT.NONE).setText("Buttons:"); final Combo buttons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); buttons.add("1"); buttons.add("2"); buttons.select(0); new Label(shell, SWT.NONE).setText("Return:"); final Label returnVal = new Label(shell, SWT.NONE); returnVal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button button = new Button(shell, SWT.PUSH); button.setText("Show Message"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { returnVal.setText(""); returnVal.setText(icons.getSelectionIndex() + " " + buttons.getSelectionIndex()); } }); 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 display = new Display(); Shell shell = new Shell(); shell.setLayout(new GridLayout(1, false)); // Create a label new Label(shell, SWT.NONE).setText("This is a plain label."); // Create a vertical separator new Label(shell, SWT.SEPARATOR); // Create a label with a border new Label(shell, SWT.BORDER).setText("This is a label with a border."); // Create a horizontal separator Label separator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create a label with an image // Image image = new Image(display, "interspatial.gif"); // Label imageLabel = new Label(shell, SWT.NONE); // imageLabel.setImage(image); shell.open();// w w w.j a va2s. c o m while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:LabelExample.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(); shell.setLayout(new GridLayout(1, false)); // Create a label new Label(shell, SWT.NONE).setText("This is a plain label."); // Create a vertical separator new Label(shell, SWT.SEPARATOR); // Create a label with a border new Label(shell, SWT.BORDER).setText("This is a label with a border."); // Create a horizontal separator Label separator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create a label with an image Image image = new Image(display, "java2s.gif"); Label imageLabel = new Label(shell, SWT.NONE); imageLabel.setImage(image);/*from w ww . ja va2 s . com*/ shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet286.java
public static void main(java.lang.String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 286"); shell.setLayout(new GridLayout()); Canvas blankCanvas = new Canvas(shell, SWT.BORDER); blankCanvas.setLayoutData(new GridData(200, 200)); final Label statusLine = new Label(shell, SWT.NONE); statusLine.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar);/* ww w .j a v a2 s .c om*/ MenuItem menuItem = new MenuItem(bar, SWT.CASCADE); menuItem.setText("Test"); Menu menu = new Menu(bar); menuItem.setMenu(menu); for (int i = 0; i < 5; i++) { MenuItem item = new MenuItem(menu, SWT.PUSH); item.setText("Item " + i); item.addArmListener(e -> statusLine.setText(((MenuItem) e.getSource()).getText())); } shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet235.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("The SWT.Settings Event"); shell.setLayout(new GridLayout()); Label label = new Label(shell, SWT.WRAP); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); label.setText("Change a system setting and the table below will be updated."); final Table table = new Table(shell, SWT.BORDER); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TableColumn column = new TableColumn(table, SWT.NONE); column = new TableColumn(table, SWT.NONE); column.setWidth(150);//from w w w. ja va2s .co m column = new TableColumn(table, SWT.NONE); for (int i = 0; i < colorIds.length; i++) { TableItem item = new TableItem(table, SWT.NONE); Color color = display.getSystemColor(colorIds[i]); item.setText(0, colorNames[i]); item.setBackground(1, color); item.setText(2, color.toString()); } TableColumn[] columns = table.getColumns(); columns[0].pack(); columns[2].pack(); display.addListener(SWT.Settings, event -> { for (int i = 0; i < colorIds.length; i++) { Color color = display.getSystemColor(colorIds[i]); TableItem item = table.getItem(i); item.setBackground(1, color); } TableColumn[] columns1 = table.getColumns(); columns1[0].pack(); columns1[2].pack(); }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:DetectSystemSettingChange.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("The SWT.Settings Event"); shell.setLayout(new GridLayout()); Label label = new Label(shell, SWT.WRAP); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); label.setText("Change a system setting and the table below will be updated."); final Table table = new Table(shell, SWT.BORDER); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); TableColumn column = new TableColumn(table, SWT.NONE); column = new TableColumn(table, SWT.NONE); column.setWidth(150);/*from www . ja v a 2 s . c o m*/ column = new TableColumn(table, SWT.NONE); for (int i = 0; i < colorIds.length; i++) { TableItem item = new TableItem(table, SWT.NONE); Color color = display.getSystemColor(colorIds[i]); item.setText(0, colorNames[i]); item.setBackground(1, color); item.setText(2, color.toString()); } TableColumn[] columns = table.getColumns(); columns[0].pack(); columns[2].pack(); display.addListener(SWT.Settings, new Listener() { public void handleEvent(Event event) { for (int i = 0; i < colorIds.length; i++) { Color color = display.getSystemColor(colorIds[i]); TableItem item = table.getItem(i); item.setBackground(1, color); } TableColumn[] columns = table.getColumns(); columns[0].pack(); columns[2].pack(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) 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 av a2 s .c om } // 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: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 w w w .j av a 2s . co m*/ 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:org.eclipse.swt.snippets.Snippet340.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 340"); shell.setLayout(new GridLayout()); shell.setText("Description Relation Example"); // (works with either a Label or a READ_ONLY Text) final Label liveLabel = new Label(shell, SWT.BORDER | SWT.READ_ONLY); // final Text liveLabel = new Text(shell, SWT.BORDER | SWT.READ_ONLY); liveLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); liveLabel.setText("Live region messages go here"); new Label(shell, SWT.NONE).setText("Type an integer from 1 to 4:"); final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER); textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); textField.addModifyListener(e -> { String textValue = textField.getText(); String message = textValue + " is not valid input."; try {/*from ww w.j a v a2s . c o m*/ int value = Integer.parseInt(textValue); switch (value) { case 1: message = "One for the money,"; break; case 2: message = "Two for the show,"; break; case 3: message = "Three to get ready,"; break; case 4: message = "And four to go!"; break; } } catch (NumberFormatException ex) { } liveLabel.setText(message); textField.getAccessible().sendEvent(ACC.EVENT_DESCRIPTION_CHANGED, null); textField.setSelection(0, textField.getCharCount()); }); textField.getAccessible().addRelation(ACC.RELATION_DESCRIBED_BY, liveLabel.getAccessible()); liveLabel.getAccessible().addRelation(ACC.RELATION_DESCRIPTION_FOR, textField.getAccessible()); textField.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getDescription(AccessibleEvent event) { event.result = liveLabel.getText(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }