List of usage examples for org.eclipse.swt.widgets Label setText
public void setText(String text)
From source file:org.eclipse.swt.snippets.Snippet295.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Shell"); FillLayout fillLayout = new FillLayout(); fillLayout.marginWidth = 10;/*from w ww .ja v a2 s. c o m*/ fillLayout.marginHeight = 10; shell.setLayout(fillLayout); Button open = new Button(shell, SWT.PUSH); open.setText("Prompt for a String"); open.addSelectionListener(widgetSelectedAdapter(e -> { final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText("Dialog Shell"); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = 10; formLayout.marginHeight = 10; formLayout.spacing = 10; dialog.setLayout(formLayout); Label label = new Label(dialog, SWT.NONE); label.setText("Type a String:"); FormData data = new FormData(); label.setLayoutData(data); Button cancel = new Button(dialog, SWT.PUSH); cancel.setText("Cancel"); data = new FormData(); data.width = 60; data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); cancel.setLayoutData(data); cancel.addSelectionListener(widgetSelectedAdapter(event -> { System.out.println("User cancelled dialog"); dialog.close(); })); final Text text = new Text(dialog, SWT.BORDER); data = new FormData(); data.width = 200; data.left = new FormAttachment(label, 0, SWT.DEFAULT); data.right = new FormAttachment(100, 0); data.top = new FormAttachment(label, 0, SWT.CENTER); data.bottom = new FormAttachment(cancel, 0, SWT.DEFAULT); text.setLayoutData(data); Button ok = new Button(dialog, SWT.PUSH); ok.setText("OK"); data = new FormData(); data.width = 60; data.right = new FormAttachment(cancel, 0, SWT.DEFAULT); data.bottom = new FormAttachment(100, 0); ok.setLayoutData(data); ok.addSelectionListener(widgetSelectedAdapter(event -> { System.out.println("User typed: " + text.getText()); dialog.close(); })); dialog.setDefaultButton(ok); dialog.pack(); dialog.open(); })); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SystemIconImage.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_ERROR)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_ERROR"); label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_INFORMATION"); label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_WARNING)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_WARNING"); label = new Label(shell, SWT.NONE); label.setImage(display.getSystemImage(SWT.ICON_QUESTION)); label = new Label(shell, SWT.NONE); label.setText("SWT.ICON_QUESTION"); shell.setSize(400, 350);/*from w w w . ja va2s . co m*/ 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();// w w w . ja va 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:EventListenerGeneral.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER); shell.setLayout(new GridLayout()); Listener listener = new MouseEnterExitListener(); label.setText("Point your cursor here ..."); label.setBounds(30, 30, 200, 30);/*from w w w . ja v a2s. co m*/ label.addListener(SWT.MouseEnter, listener); label.addListener(SWT.MouseExit, listener); shell.setSize(260, 120); shell.open(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
From source file:MouseTrackAdapter.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER); shell.setLayout(new GridLayout()); MouseTrackAdapter listener = new MouseEnterExitListener(); label.setText("Point your cursor here ..."); label.setBounds(30, 30, 200, 30);/*from w w w . j av a 2 s. c o m*/ label.addMouseTrackListener(listener); shell.setSize(260, 120); shell.open(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } }
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. 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:DragDropOperation.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Label label = new Label(shell, SWT.BORDER); label.setText("Drag Source"); DragSource source = new DragSource(label, DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK); source.setTransfer(new Transfer[] { TextTransfer.getInstance() }); source.addDragListener(new DragSourceAdapter() { public void dragSetData(DragSourceEvent event) { event.data = "Text Transferred"; }//from w w w .j a v a 2 s . co m public void dragFinished(DragSourceEvent event) { if (event.doit) { String operation = null; switch (event.detail) { case DND.DROP_MOVE: operation = "moved"; break; case DND.DROP_COPY: operation = "copied"; break; case DND.DROP_LINK: operation = "linked"; break; case DND.DROP_NONE: operation = "disallowed"; break; default: operation = "unknown"; break; } label.setText("Drag Source (data " + operation + ")"); } else { label.setText("Drag Source (drag cancelled)"); } } }); final Text text = new Text(shell, SWT.BORDER | SWT.MULTI); text.setText("Drop Target"); DropTarget target = new DropTarget(text, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK); target.setTransfer(new Transfer[] { TextTransfer.getInstance() }); target.addDropListener(new DropTargetAdapter() { public void dragEnter(DropTargetEvent event) { if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; } public void dragOperationChanged(DropTargetEvent event) { if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; } public void drop(DropTargetEvent event) { String operation = null; switch (event.detail) { case DND.DROP_MOVE: operation = "moved"; break; case DND.DROP_COPY: operation = "copied"; break; case DND.DROP_LINK: operation = "linked"; break; case DND.DROP_NONE: operation = "disallowed"; break; default: operation = "unknown"; break; } text.append("\n" + operation + (String) event.data); } }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:GridLayoutSimpleDmo.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(4, false); gridLayout.verticalSpacing = 8;/*from w w w. j a v a2 s . c om*/ shell.setLayout(gridLayout); Label label = new Label(shell, SWT.NULL); label.setText("Title: "); Text title = new Text(shell, SWT.SINGLE | SWT.BORDER); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; title.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Author(s): "); Text authors = new Text(shell, SWT.SINGLE | SWT.BORDER); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; authors.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Cover: "); gridData = new GridData(); gridData.verticalSpan = 3; label.setLayoutData(gridData); CLabel cover = new CLabel(shell, SWT.NULL); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 1; gridData.verticalSpan = 3; gridData.heightHint = 100; gridData.widthHint = 100; cover.setLayoutData(gridData); label = new Label(shell, SWT.NULL); label.setText("Pages"); Text pages = new Text(shell, SWT.SINGLE | SWT.BORDER); pages.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); label = new Label(shell, SWT.NULL); label.setText("Publisher"); Text publisher = new Text(shell, SWT.SINGLE | SWT.BORDER); publisher.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); label = new Label(shell, SWT.NULL); label.setText("Rating"); Combo rating = new Combo(shell, SWT.READ_ONLY); rating.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); rating.add("5"); rating.add("4"); rating.add("3"); rating.add("2"); rating.add("1"); label = new Label(shell, SWT.NULL); label.setText("Abstract:"); Text bookAbstract = new Text(shell, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); gridData.horizontalSpan = 3; gridData.grabExcessVerticalSpace = true; bookAbstract.setLayoutData(gridData); Button enter = new Button(shell, SWT.PUSH); enter.setText("Enter"); gridData = new GridData(); gridData.horizontalSpan = 4; gridData.horizontalAlignment = GridData.END; enter.setLayoutData(gridData); title.setText("Professional Java Interfaces with SWT/JFace"); authors.setText("Jack Li Guojie"); pages.setText("500pp"); publisher.setText("John Wiley & Sons"); cover.setBackground(new Image(display, "yourFile.gif")); bookAbstract.setText("SWT/JFace. "); shell.setSize(450, 400); 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 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:org.eclipse.swt.snippets.Snippet84.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 84"); shell.setLayout(new FillLayout()); final Label label = new Label(shell, SWT.BORDER); label.setText("Drag Source"); DragSource source = new DragSource(label, DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK); source.setTransfer(TextTransfer.getInstance()); source.addDragListener(new DragSourceAdapter() { @Override/*w w w. ja v a 2 s.co m*/ public void dragSetData(DragSourceEvent event) { event.data = "Text Transferred"; } @Override public void dragFinished(DragSourceEvent event) { if (event.doit) { String operation = null; switch (event.detail) { case DND.DROP_MOVE: operation = "moved"; break; case DND.DROP_COPY: operation = "copied"; break; case DND.DROP_LINK: operation = "linked"; break; case DND.DROP_NONE: operation = "disallowed"; break; default: operation = "unknown"; break; } label.setText("Drag Source (data " + operation + ")"); } else { label.setText("Drag Source (drag cancelled)"); } } }); final Text text = new Text(shell, SWT.BORDER | SWT.MULTI); text.setText("Drop Target"); DropTarget target = new DropTarget(text, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK); target.setTransfer(TextTransfer.getInstance()); target.addDropListener(new DropTargetAdapter() { @Override public void dragEnter(DropTargetEvent event) { if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; } @Override public void dragOperationChanged(DropTargetEvent event) { if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY; } @Override public void drop(DropTargetEvent event) { String operation = null; switch (event.detail) { case DND.DROP_MOVE: operation = "moved"; break; case DND.DROP_COPY: operation = "copied"; break; case DND.DROP_LINK: operation = "linked"; break; case DND.DROP_NONE: operation = "disallowed"; break; default: operation = "unknown"; break; } text.append("\n" + operation + (String) event.data); } }); shell.setSize(400, 400); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }