List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:org.eclipse.swt.snippets.Snippet284.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("URLTransfer"); shell.setLayout(new FillLayout()); final Label label1 = new Label(shell, SWT.BORDER); label1.setText("http://www.eclipse.org"); final Label label2 = new Label(shell, SWT.BORDER); setDragSource(label1);/* ww w. j a va2 s . c om*/ setDropTarget(label2); shell.setSize(600, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet278.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 278"); shell.setBounds(10, 10, 300, 100);// ww w. j a v a 2 s .c o m shell.setLayout(new FillLayout()); final Label label = new Label(shell, SWT.NONE); label.setText("resize the Shell then hover over this Label"); label.addListener(SWT.MouseEnter, event -> { Point requiredSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point labelSize = label.getSize(); boolean fullyVisible = requiredSize.x <= labelSize.x && requiredSize.y <= labelSize.y; System.out.println("Label is fully visible: " + fullyVisible); label.setToolTipText(fullyVisible ? null : label.getText()); }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet71.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 71"); shell.pack();/* w w w .j a v a 2s .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(); }
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);/*www . j a va 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, 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:DecroationStyles.java
public static void main(String[] args) { Display display = new Display(); Shell composite = new Shell(display); composite.setText("Decorations Example"); composite.setLayout(new GridLayout(3, true)); // The SWT.BORDER style Decorations d = new Decorations(composite, SWT.BORDER); // d = new Decorations(composite, SWT.CLOSE); // d = new Decorations(composite, SWT.MIN); // d = new Decorations(composite, SWT.MAX); // d = new Decorations(composite, SWT.NO_TRIM); // d = new Decorations(composite, SWT.RESIZE); // d = new Decorations(composite, SWT.TITLE); // d = new Decorations(composite, SWT.ON_TOP); // d = new Decorations(composite, SWT.TOOL); d.setLayoutData(new GridData(GridData.FILL_BOTH)); d.setLayout(new FillLayout()); new Label(d, SWT.CENTER).setText("SWT.BORDER"); composite.open();//ww w .ja va 2 s. c o m while (!composite.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet152.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 152"); FormLayout layout = new FormLayout(); shell.setLayout(layout);/*from w w w . j av a 2s .c om*/ final Label label = new Label(shell, SWT.BORDER); Listener armListener = event -> { MenuItem item = (MenuItem) event.widget; label.setText(item.getText()); label.update(); }; Listener showListener = event -> { Menu menu = (Menu) event.widget; MenuItem item = menu.getParentItem(); if (item != null) { label.setText(item.getText()); label.update(); } }; Listener hideListener = 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.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);/* w w w.j av a 2 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:FormLayoutSingleLine.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); 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);//from w w w . j av a 2 s .co m FormData data = new FormData(200, 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:org.eclipse.swt.snippets.Snippet153.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 153"); shell.setBounds(10, 10, 200, 200);//from w w w. j a va2s. c om final ToolBar bar = new ToolBar(shell, SWT.BORDER); bar.setBounds(10, 10, 150, 50); final Label statusLine = new Label(shell, SWT.BORDER); statusLine.setBounds(10, 90, 150, 30); new ToolItem(bar, SWT.NONE).setText("item 1"); new ToolItem(bar, SWT.NONE).setText("item 2"); new ToolItem(bar, SWT.NONE).setText("item 3"); bar.addMouseMoveListener(e -> { ToolItem item = bar.getItem(new Point(e.x, e.y)); String name = ""; if (item != null) { name = item.getText(); } if (!statusText.equals(name)) { statusLine.setText(name); statusText = name; } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet34.java
public static void main(String[] args) { Display display = new Display(); Image image = new Image(display, 16, 16); Color color = display.getSystemColor(SWT.COLOR_RED); GC gc = new GC(image); gc.setBackground(color);/*from w ww .ja v a 2 s. c o m*/ gc.fillRectangle(image.getBounds()); gc.dispose(); Shell shell = new Shell(display); shell.setText("Snippet 34"); Label label = new Label(shell, SWT.BORDER); Rectangle clientArea = shell.getClientArea(); label.setLocation(clientArea.x, clientArea.y); label.setImage(image); label.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }