List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:SashFormThreeChildren.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); SashForm form = new SashForm(shell, SWT.HORIZONTAL); form.setLayout(new FillLayout()); Composite child1 = new Composite(form, SWT.NONE); child1.setLayout(new FillLayout()); new Label(child1, SWT.NONE).setText("Label in pane 1"); Composite child2 = new Composite(form, SWT.NONE); child2.setLayout(new FillLayout()); new Button(child2, SWT.PUSH).setText("Button in pane2"); Composite child3 = new Composite(form, SWT.NONE); child3.setLayout(new FillLayout()); new Label(child3, SWT.PUSH).setText("Label in pane3"); form.setWeights(new int[] { 30, 40, 30 }); shell.open();/* w ww . j ava 2 s . co m*/ while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Snippet144.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new RowLayout(SWT.VERTICAL)); final Table table = new Table(shell, SWT.VIRTUAL | SWT.BORDER); table.addListener(SWT.SetData, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem) event.item; int index = table.indexOf(item); item.setText("Item " + index); System.out.println(item.getText()); }/*from ww w. j a va2s . co m*/ }); table.setLayoutData(new RowData(200, 200)); Button button = new Button(shell, SWT.PUSH); button.setText("Add Items"); final Label label = new Label(shell, SWT.NONE); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { long t1 = System.currentTimeMillis(); table.setItemCount(COUNT); long t2 = System.currentTimeMillis(); label.setText("Items: " + COUNT + ", Time: " + (t2 - t1) + " (ms)"); shell.layout(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:DialogLayoutDemo.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); Label label = new Label(shell, SWT.WRAP); label.setText("This is a long text string that will wrap when the dialog is resized."); List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); list.setItems(new String[] { "Item 1", "Item 2" }); Button button1 = new Button(shell, SWT.PUSH); button1.setText("OK"); Button button2 = new Button(shell, SWT.PUSH); button2.setText("Cancel"); final int insetX = 4, insetY = 4; FormLayout formLayout = new FormLayout(); formLayout.marginWidth = insetX;/*from ww w. j a v a 2s . c o m*/ formLayout.marginHeight = insetY; shell.setLayout(formLayout); Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT); final FormData labelData = new FormData(size.x, SWT.DEFAULT); labelData.left = new FormAttachment(0, 0); labelData.right = new FormAttachment(100, 0); label.setLayoutData(labelData); shell.addListener(SWT.Resize, new Listener() { public void handleEvent(Event e) { Rectangle rect = shell.getClientArea(); labelData.width = rect.width - insetX * 2; shell.layout(); } }); FormData button2Data = new FormData(); button2Data.right = new FormAttachment(100, -insetX); button2Data.bottom = new FormAttachment(100, 0); button2.setLayoutData(button2Data); FormData button1Data = new FormData(); button1Data.right = new FormAttachment(button2, -insetX); button1Data.bottom = new FormAttachment(100, 0); button1.setLayoutData(button1Data); FormData listData = new FormData(); listData.left = new FormAttachment(0, 0); listData.right = new FormAttachment(100, 0); listData.top = new FormAttachment(label, insetY); listData.bottom = new FormAttachment(button2, -insetY); list.setLayoutData(listData); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet344.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 344"); shell.setLayout(new GridLayout(1, false)); Button button = new Button(shell, SWT.PUSH); button.setText("Click me"); button.addSelectionListener(widgetSelectedAdapter(e -> { Shell shell2 = new Shell(SWT.TOOL | SWT.RESIZE | SWT.CLOSE | SWT.MAX); shell2.setLayout(new GridLayout(1, false)); shell2.setText("Palette"); Label l = new Label(shell2, SWT.LEFT); l.setText("This is a SWT.TOOL Shell"); Point origin = shell.getLocation(); origin.x += 100;/*from w w w. j a va2s . co m*/ origin.y += 100; shell2.pack(); shell2.open(); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet104.java
public static void main(String[] args) { final Display display = new Display(); final int[] count = new int[] { 4 }; final Image image = new Image(display, 300, 300); GC gc = new GC(image); gc.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); gc.fillRectangle(image.getBounds()); gc.drawText("Splash Screen", 10, 10); gc.dispose();//from ww w.j a v a 2 s.c om final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]); Label label = new Label(splash, SWT.NONE); label.setImage(image); FormLayout layout = new FormLayout(); splash.setLayout(layout); FormData labelData = new FormData(); labelData.right = new FormAttachment(100, 0); labelData.bottom = new FormAttachment(100, 0); label.setLayoutData(labelData); FormData progressData = new FormData(); progressData.left = new FormAttachment(0, 5); progressData.right = new FormAttachment(100, -5); progressData.bottom = new FormAttachment(100, -5); bar.setLayoutData(progressData); splash.pack(); Rectangle splashRect = splash.getBounds(); Rectangle displayRect = display.getBounds(); int x = (displayRect.width - splashRect.width) / 2; int y = (displayRect.height - splashRect.height) / 2; splash.setLocation(x, y); splash.open(); display.asyncExec(() -> { Shell[] shells = new Shell[count[0]]; for (int i1 = 0; i1 < count[0]; i1++) { shells[i1] = new Shell(display); shells[i1].setSize(300, 300); shells[i1].addListener(SWT.Close, e -> --count[0]); bar.setSelection(i1 + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i2 = 0; i2 < count[0]; i2++) { shells[i2].setText("SWT Snippet 104 - " + (i2 + 1)); shells[i2].open(); } }); while (count[0] != 0) { 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 w ww .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:StatusLineUpdateWhenMenuItemArmed.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); FormLayout layout = new FormLayout(); shell.setLayout(layout);// w ww. j av a2 s. c om final Label label = new Label(shell, SWT.BORDER); Listener armListener = new Listener() { public void handleEvent(Event event) { MenuItem item = (MenuItem) event.widget; label.setText(item.getText()); label.update(); } }; Listener showListener = new Listener() { public void handleEvent(Event event) { Menu menu = (Menu) event.widget; MenuItem item = menu.getParentItem(); if (item != null) { label.setText(item.getText()); label.update(); } } }; Listener hideListener = new Listener() { public void handleEvent(Event event) { label.setText(""); label.update(); } }; FormData labelData = new FormData(); labelData.left = new FormAttachment(0); labelData.right = new FormAttachment(100); labelData.bottom = new FormAttachment(100); label.setLayoutData(labelData); Menu menuBar = new Menu(shell, SWT.BAR); shell.setMenuBar(menuBar); MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE); fileItem.setText("File"); fileItem.addListener(SWT.Arm, armListener); MenuItem editItem = new MenuItem(menuBar, SWT.CASCADE); editItem.setText("Edit"); editItem.addListener(SWT.Arm, armListener); Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); fileMenu.addListener(SWT.Hide, hideListener); fileMenu.addListener(SWT.Show, showListener); fileItem.setMenu(fileMenu); String[] fileStrings = { "New", "Close", "Exit" }; for (int i = 0; i < fileStrings.length; i++) { MenuItem item = new MenuItem(fileMenu, SWT.PUSH); item.setText(fileStrings[i]); item.addListener(SWT.Arm, armListener); } Menu editMenu = new Menu(shell, SWT.DROP_DOWN); editMenu.addListener(SWT.Hide, hideListener); editMenu.addListener(SWT.Show, showListener); String[] editStrings = { "Cut", "Copy", "Paste" }; editItem.setMenu(editMenu); for (int i = 0; i < editStrings.length; i++) { MenuItem item = new MenuItem(editMenu, SWT.PUSH); item.setText(editStrings[i]); item.addListener(SWT.Arm, armListener); } 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"); }/*w w w.ja 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:TimeStopWhenButtonPressing.java
public static void main(String[] args) { final Display display = new Display(); final Color red = display.getSystemColor(SWT.COLOR_RED); final Color blue = display.getSystemColor(SWT.COLOR_BLUE); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Button button = new Button(shell, SWT.PUSH); button.setText("Stop Timer"); final Label label = new Label(shell, SWT.BORDER); label.setBackground(red);//from w ww . j av a 2s . co m final int time = 500; final Runnable timer = new Runnable() { public void run() { if (label.isDisposed()) return; Color color = label.getBackground().equals(red) ? blue : red; label.setBackground(color); display.timerExec(time, this); } }; display.timerExec(time, timer); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { display.timerExec(-1, timer); } }); button.pack(); label.setLayoutData(new RowData(button.getSize())); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet364.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 364"); shell.setLayout(new GridLayout(1, false)); Image i = new Image(display, Snippet364.class.getResourceAsStream("eclipse.png")); Button b = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT); b.setText("Button LEFT_TO_RIGHT..."); b.setImage(i);/* w w w . jav a 2 s . c o m*/ Button b2 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT); b2.setText("Button RIGHT_TO_LEFT..."); b2.setImage(i); new Label(shell, SWT.NONE).setText("with FLIP_TEXT_DIRECTION:"); Button b3 = new Button(shell, SWT.PUSH | SWT.LEFT_TO_RIGHT | SWT.FLIP_TEXT_DIRECTION); b3.setText("Button LEFT_TO_RIGHT..."); b3.setImage(i); Button b4 = new Button(shell, SWT.PUSH | SWT.RIGHT_TO_LEFT | SWT.FLIP_TEXT_DIRECTION); b4.setText("Button RIGHT_TO_LEFT..."); b4.setImage(i); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); i.dispose(); }