List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:org.eclipse.swt.snippets.Snippet93.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 93"); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NONE); GC gc = new GC(label); Point size = gc.textExtent("Hello"); gc.dispose();/* w ww . j a v a 2s .co m*/ label.setText("Hello -> " + size); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet32.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 32"); Label label = new Label(shell, SWT.NONE); label.setText("Can't find icon for .bmp"); Image image = null;//from w ww .ja v a 2 s . c o m Program p = Program.findProgram(".bmp"); if (p != null) { ImageData data = p.getImageData(); if (data != null) { image = new Image(display, data); label.setImage(image); } } label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (image != null) image.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet276.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 276"); shell.setBounds(200, 200, 400, 400); Label label = new Label(shell, SWT.NONE); label.setText("click in shell to print display-relative coordinate"); Listener listener = event -> {//from w ww . ja v a 2s .c o m Point point = new Point(event.x, event.y); System.out.println(display.map((Control) event.widget, null, point)); }; shell.addListener(SWT.MouseDown, listener); label.addListener(SWT.MouseDown, listener); Rectangle clientArea = shell.getClientArea(); label.setLocation(clientArea.x, clientArea.y); label.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet69.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 69"); Label label = new Label(shell, SWT.NONE | SWT.BORDER); label.setText("Name"); Text text = new Text(shell, SWT.NONE); FormLayout layout = new FormLayout(); layout.marginWidth = layout.marginHeight = 5; shell.setLayout(layout);/* w ww .j a va 2 s . co m*/ GC gc = new GC(text); FontMetrics fm = gc.getFontMetrics(); double charWidth = fm.getAverageCharacterWidth(); int width = text.computeSize((int) (charWidth * 8), SWT.DEFAULT).x; gc.dispose(); FormData data = new FormData(width, SWT.DEFAULT); text.setLayoutData(data); data.left = new FormAttachment(label, 5); data.top = new FormAttachment(label, 0, SWT.CENTER); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ExpandBarIconAddingSystem.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("ExpandBar Example"); ExpandBar bar = new ExpandBar(shell, SWT.V_SCROLL); Image image = new Image(display, "yourFile.gif"); // First item Composite composite = new Composite(bar, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10; layout.verticalSpacing = 10;//from ww w . j a v a2 s.c om composite.setLayout(layout); Label label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(composite, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(composite, SWT.NONE); label.setText("SWT.ICON_QUESTION"); ExpandItem item0 = new ExpandItem(bar, SWT.NONE, 0); item0.setText("What is your favorite button"); item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); item0.setControl(composite); item0.setImage(image); item0.setExpanded(true); bar.setSpacing(8); shell.setSize(400, 350); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } image.dispose(); display.dispose(); }
From source file: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); final Shell splash = new Shell(SWT.ON_TOP); final ProgressBar bar = new ProgressBar(splash, SWT.NONE); bar.setMaximum(count[0]);//w ww . j av a 2 s . c o m 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(new Runnable() { public void run() { Shell[] shells = new Shell[count[0]]; for (int i = 0; i < count[0]; i++) { shells[i] = new Shell(display); shells[i].setSize(300, 300); shells[i].addListener(SWT.Close, new Listener() { public void handleEvent(Event e) { --count[0]; } }); bar.setSelection(i + 1); try { Thread.sleep(1000); } catch (Throwable e) { } } splash.close(); image.dispose(); for (int i = 0; i < count[0]; i++) { shells[i].open(); } } }); while (count[0] != 0) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet335.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 335"); shell.setLayout(new GridLayout()); Label label = new Label(shell, SWT.WRAP | SWT.BORDER); GridData labelData = new GridData(); labelData.widthHint = 10; /* default width */ labelData.horizontalAlignment = SWT.FILL; /* grow to fill available width */ label.setLayoutData(labelData);/*from w w w . j a v a 2 s. co m*/ label.setText( "Snippets are minimal stand-alone programs that demonstrate specific techniques or functionality."); new Button(shell, SWT.PUSH).setText("This button determines the Shell's width"); /* do an initial pack() so that the Shell determines its required width */ shell.pack(); /* update the Label's width hint to match what the layout allocated for it */ labelData.widthHint = label.getBounds().width; /* * do a second pack() so that the Label will compute its required height * based on its correct width instead of its previously-set default width */ shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet108.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 108"); Label label = new Label(shell, SWT.NONE); label.setText("Enter your name:"); Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new RowData(100, SWT.DEFAULT)); Button ok = new Button(shell, SWT.PUSH); ok.setText("OK"); ok.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("OK"))); Button cancel = new Button(shell, SWT.PUSH); cancel.setText("Cancel"); cancel.addSelectionListener(widgetSelectedAdapter(e -> System.out.println("Cancel"))); shell.setDefaultButton(cancel);/*from w w w . ja va2 s .c o m*/ shell.setLayout(new RowLayout()); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet65.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 65"); 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("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 w ww. ja v a 2 s.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, 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.Snippet78.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 78"); shell.setLayout(new FillLayout()); final Label label1 = new Label(shell, SWT.BORDER); label1.setText("TEXT"); final Label label2 = new Label(shell, SWT.BORDER); setDragDrop(label1);//from w w w.j av a2 s .c om setDragDrop(label2); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }