List of usage examples for org.eclipse.swt.widgets Label setText
public void setText(String text)
From source file:FormLayoutDialogDemo.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("Some text for your dialog."); List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); list.setItems(new String[] { "Item 1", "Item2" }); 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 . j a v a 2 s . c om*/ 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:Snippet65.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", "Item2" }); 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 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:FontDialogColorFontData.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Font Chooser"); shell.setLayout(new GridLayout(2, false)); final Label fontLabel = new Label(shell, SWT.NONE); fontLabel.setText("The selected font"); Button button = new Button(shell, SWT.PUSH); button.setText("Font..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { Font font = null;//from w w w . j av a2 s. c om Color color = null; FontDialog dlg = new FontDialog(shell); if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { if (font != null) font.dispose(); if (color != null) color.dispose(); font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); shell.pack(); if (font != null) font.dispose(); if (color != null) color.dispose(); } } }); 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 ww w. j a va 2 s . c om 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.Snippet350.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 350"); shell.setLayout(new GridLayout(2, false)); shell.setText("Accessible Relations"); Label nameLabel = new Label(shell, SWT.NONE); nameLabel.setText("Name:"); Text nameText = new Text(shell, SWT.BORDER); nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Accessible accNameLabel = nameLabel.getAccessible(); Accessible accNameText = nameText.getAccessible(); accNameLabel.addRelation(ACC.RELATION_LABEL_FOR, accNameText); accNameText.addRelation(ACC.RELATION_LABELLED_BY, accNameLabel); Group addressGroup = new Group(shell, SWT.NONE); addressGroup.setText("Address"); addressGroup.setLayout(new GridLayout(2, false)); addressGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Label streetLabel = new Label(addressGroup, SWT.NONE); streetLabel.setText("Street:"); Text streetText = new Text(addressGroup, SWT.BORDER); streetText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Accessible accStreetLabel = streetLabel.getAccessible(); Accessible accStreetText = streetText.getAccessible(); accStreetLabel.addRelation(ACC.RELATION_LABEL_FOR, accStreetText); accStreetText.addRelation(ACC.RELATION_LABELLED_BY, accStreetLabel); Label cityLabel = new Label(addressGroup, SWT.NONE); cityLabel.setText("City:"); Text cityText = new Text(addressGroup, SWT.BORDER); cityText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Accessible accCityLabel = cityLabel.getAccessible(); Accessible accCityText = cityText.getAccessible(); accCityLabel.addRelation(ACC.RELATION_LABEL_FOR, accCityText); accCityText.addRelation(ACC.RELATION_LABELLED_BY, accCityLabel); Accessible accAddressGroup = addressGroup.getAccessible(); accStreetText.addRelation(ACC.RELATION_MEMBER_OF, accAddressGroup); accStreetText.addRelation(ACC.RELATION_LABELLED_BY, accAddressGroup); accCityText.addRelation(ACC.RELATION_MEMBER_OF, accAddressGroup); accCityText.addRelation(ACC.RELATION_LABELLED_BY, accAddressGroup); shell.pack();/*from w ww . ja v a 2 s. co m*/ 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 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, 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:Snippet93.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); GC gc = new GC(label); Point size = gc.textExtent("Hello"); gc.dispose();//from w w w .j av a 2 s . co m label.setText("Hello -> " + size); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:DialogClass.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Dialog Example"); shell.setSize(300, 200);//from w w w . j a v a 2s.c o m shell.open(); final Button button = new Button(shell, SWT.PUSH); button.setText("Delete File"); button.setBounds(20, 40, 80, 25); final Text text = new Text(shell, SWT.SHADOW_IN); text.setBounds(140, 40, 100, 25); final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); dialog.setText("Delete File"); dialog.setSize(250, 150); final Button buttonOK = new Button(dialog, SWT.PUSH); buttonOK.setText("OK"); buttonOK.setBounds(20, 55, 80, 25); Button buttonCancel = new Button(dialog, SWT.PUSH); buttonCancel.setText("Cancel"); buttonCancel.setBounds(120, 55, 80, 25); final Label label = new Label(dialog, SWT.NONE); label.setText("Delete the file?"); label.setBounds(20, 15, 100, 20); Listener listener = new Listener() { public void handleEvent(Event event) { if (event.widget == buttonOK) { deleteFlag = true; } else { deleteFlag = false; } dialog.close(); } }; buttonOK.addListener(SWT.Selection, listener); buttonCancel.addListener(SWT.Selection, listener); Listener buttonListener = new Listener() { public void handleEvent(Event event) { dialog.open(); } }; button.addListener(SWT.Selection, buttonListener); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (deleteFlag) { text.setText("File deleted."); } else { text.setText("File not deleted."); } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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();/*from w w w.ja va 2 s . co m*/ label.setText("Hello -> " + size); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:SWTButtonAction.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(200, 200);// ww w . j ava 2 s . c om shell.setText("Dialogs"); shell.open(); final Button opener = new Button(shell, SWT.PUSH); opener.setText("Click Me"); opener.setBounds(20, 20, 50, 25); final Text text = new Text(shell, SWT.SHADOW_IN); text.setBounds(80, 20, 100, 25); final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); dialog.setText("Dialog"); dialog.setSize(150, 100); final Label label = new Label(dialog, SWT.NONE); label.setText("OK to proceed?"); label.setBounds(35, 5, 100, 20); final Button okButton = new Button(dialog, SWT.PUSH); okButton.setBounds(20, 35, 40, 25); okButton.setText("OK"); Button cancelButton = new Button(dialog, SWT.PUSH); cancelButton.setBounds(70, 35, 40, 25); cancelButton.setText("Cancel"); final boolean[] response = new boolean[1]; response[0] = true; Listener listener = new Listener() { public void handleEvent(Event event) { if (event.widget == okButton) { response[0] = true; } else { response[0] = false; } dialog.close(); } }; okButton.addListener(SWT.Selection, listener); cancelButton.addListener(SWT.Selection, listener); Listener openerListener = new Listener() { public void handleEvent(Event event) { dialog.open(); } }; opener.addListener(SWT.Selection, openerListener); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } if (response[0]) { text.setText("You clicked OK"); } else { text.setText("You clicked Cancel"); } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }