List of usage examples for org.eclipse.swt.widgets Label setText
public void setText(String text)
From source file:GetInput.java
/** * Creates the main window's contents//from w w w . ja v a2 s . c o m * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); // Create a label to display what the user typed in final Label label = new Label(composite, SWT.NONE); label.setText("This will display the user input from InputDialog"); // Create the button to launch the error dialog Button show = new Button(composite, SWT.PUSH); show.setText("Get Input"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters", label.getText(), new LengthValidator()); if (dlg.open() == Window.OK) { // User clicked OK; update the label with the input label.setText(dlg.getValue()); } } }); parent.pack(); return composite; }
From source file:ChooseFont.java
/** * Creates the window contents/* w ww . ja v a 2s .com*/ * * @param shell the parent shell */ private void createContents(final Shell shell) { 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) { // Create the color-change dialog FontDialog dlg = new FontDialog(shell); // Pre-fill the dialog with any previous selection if (font != null) dlg.setFontList(fontLabel.getFont().getFontData()); if (color != null) dlg.setRGB(color.getRGB()); if (dlg.open() != null) { // Dispose of any fonts or colors we have created if (font != null) font.dispose(); if (color != null) color.dispose(); // Create the new font and set it into the label font = new Font(shell.getDisplay(), dlg.getFontList()); fontLabel.setFont(font); // Create the new color and set it color = new Color(shell.getDisplay(), dlg.getRGB()); fontLabel.setForeground(color); // Call pack() to resize the window to fit the new font shell.pack(); } } }); }
From source file:InputDialog.java
private void createContents(final Shell shell) { shell.setLayout(new GridLayout(2, true)); Label label = new Label(shell, SWT.NONE); label.setText(message); GridData data = new GridData(); data.horizontalSpan = 2;//from www . ja v a 2 s . co m label.setLayoutData(data); final Text text = new Text(shell, SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; text.setLayoutData(data); Button ok = new Button(shell, SWT.PUSH); ok.setText("OK"); data = new GridData(GridData.FILL_HORIZONTAL); ok.setLayoutData(data); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { input = text.getText(); shell.close(); } }); Button cancel = new Button(shell, SWT.PUSH); cancel.setText("Cancel"); data = new GridData(GridData.FILL_HORIZONTAL); cancel.setLayoutData(data); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { input = null; shell.close(); } }); shell.setDefaultButton(ok); }
From source file:GroupExamples.java
public GroupExamples() { Group group0 = new Group(shell, SWT.NULL); group0.setLayout(new FillLayout()); Label label = new Label(group0, SWT.NULL); label.setAlignment(SWT.CENTER);// ww w.j a v a 2s .co m label.setText("a group without title."); Group group1 = new Group(shell, SWT.NULL); group1.setText("SWT.NULL"); Group group2 = new Group(shell, SWT.SHADOW_ETCHED_IN); group2.setText("SWT.SHADOW_ETCHED_IN"); Group group3 = new Group(shell, SWT.SHADOW_ETCHED_OUT); group3.setText("SWT.SHADOW_ETCHED_OUT"); Group group4 = new Group(shell, SWT.SHADOW_IN); group4.setText("SWT.SHADOW_IN"); Group group5 = new Group(shell, SWT.SHADOW_OUT); group5.setText("SWT.SHADOW_OUT"); Group[] groups = new Group[] { group0, group1, group2, group3, group4, group5 }; for (int i = 0; i < groups.length; i++) { groups[i].setBounds(10, 10 + i * 50, 300, 40); } shell.pack(); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:TabFolderExample.java
public TabFolderExample() { shell.setLayout(new FillLayout()); final TabFolder tabFolder = new TabFolder(shell, SWT.BOTTOM); Button button = new Button(tabFolder, SWT.NULL); button.setText("This is a button."); TabItem tabItem1 = new TabItem(tabFolder, SWT.NULL); tabItem1.setText("item #1"); tabItem1.setImage(icon);//from ww w .j av a 2 s. co m tabItem1.setControl(button); Text text = new Text(tabFolder, SWT.MULTI); text.setText("This is a text control."); TabItem tabItem2 = new TabItem(tabFolder, SWT.NULL); tabItem2.setText("item #2"); tabItem2.setImage(icon); tabItem2.setControl(text); Label label = new Label(tabFolder, SWT.NULL); label.setText("This is a text lable."); TabItem tabItem3 = new TabItem(tabFolder, SWT.NULL); tabItem3.setText("item #3"); tabItem3.setControl(label); tabFolder.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { System.out.println("Selected item index = " + tabFolder.getSelectionIndex()); System.out.println("Selected item = " + (tabFolder.getSelection() == null ? "null" : tabFolder.getSelection()[0].toString())); } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); //tabFolder.setSelection(new TabItem[]{tabItem2, tabItem3}); //tabFolder.setSelection(2); shell.setSize(400, 120); shell.open(); //textUser.forceFocus(); System.out.println(tabFolder.getSelectionIndex()); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:Survey.java
/** * Creates the controls for this page/*from w ww . ja v a 2 s . co m*/ */ public void createControl(Composite parent) { Label label = new Label(parent, SWT.CENTER); label.setText("Thanks!"); setControl(label); }
From source file:LabelSeparator.java
public LabelSeparator() { init();//from www . j a va2 s .c om // shell.setLayout(new RowLayout()); Label label = new Label(shell, SWT.BORDER); // Label label = new Label(shell, SWT.SEPARATOR); label.setImage(image); label.setText("Label"); label.setBounds(10, 10, 150, 150); CLabel clabel = new CLabel(shell, SWT.SHADOW_IN); clabel.setImage(image); clabel.setText("CLabel"); clabel.setBounds(170, 10, 150, 150); shell.pack(); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:SashFormExample.java
public SashFormExample() { shell.setLayout(new FillLayout()); sashForm = new SashForm(shell, SWT.HORIZONTAL); Text text1 = new Text(sashForm, SWT.CENTER); text1.setText("Text in pane #1"); Text text2 = new Text(sashForm, SWT.CENTER); text2.setText("Text in pane #2"); sashForm2 = new SashForm(sashForm, SWT.VERTICAL); final Label labelA = new Label(sashForm2, SWT.BORDER | SWT.CENTER); labelA.setText("Label in pane A"); final Label labelB = new Label(sashForm2, SWT.BORDER | SWT.CENTER); labelB.setText("Label in pane B"); text1.addControlListener(new ControlListener() { public void controlMoved(ControlEvent e) { }//from w w w. j a v a 2s . com public void controlResized(ControlEvent e) { System.out.println("Resized"); } }); sashForm.setWeights(new int[] { 1, 2, 3 }); labelA.addMouseListener(new MouseListener() { public void mouseDoubleClick(MouseEvent e) { if (sashForm2.getMaximizedControl() == labelA) sashForm2.setMaximizedControl(null); else sashForm2.setMaximizedControl(labelA); } public void mouseDown(MouseEvent e) { } public void mouseUp(MouseEvent e) { } }); shell.setSize(450, 200); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:MainClass.java
protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NULL); this.getShell().setText("ButtonTest"); GridLayout layout = new GridLayout(); container.setLayout(layout);//from ww w. ja va 2s. co m layout.numColumns = 4; layout.verticalSpacing = 9; Label label; label = new Label(container, SWT.NONE); label.setText("Button Type"); label = new Label(container, SWT.NONE); label.setText("NONE"); label = new Label(container, SWT.NONE); label.setText("BORDER"); label = new Label(container, SWT.NONE); label.setText("FLAT"); createLabel(container, SWT.NONE, "Push"); createButton(container, SWT.PUSH, "button1"); createButton(container, SWT.BORDER, "button2"); createButton(container, SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Radio"); createButton(container, SWT.RADIO, "button1"); createButton(container, SWT.RADIO | SWT.BORDER, "button2"); createButton(container, SWT.RADIO | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Toggle"); createButton(container, SWT.TOGGLE, "button1"); createButton(container, SWT.TOGGLE | SWT.BORDER, "button2"); createButton(container, SWT.TOGGLE | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Check"); createButton(container, SWT.CHECK, "button1"); createButton(container, SWT.CHECK | SWT.BORDER, "button2"); createButton(container, SWT.CHECK | SWT.FLAT, "button3"); createLabel(container, SWT.NONE, "Arrow | Left"); createButton(container, SWT.ARROW | SWT.LEFT, "button1"); createButton(container, SWT.ARROW | SWT.LEFT | SWT.BORDER, "button2"); createButton(container, SWT.ARROW | SWT.LEFT | SWT.FLAT, "button3"); return container; }
From source file:TabbedShellExample.java
public GridComposite(Composite c) { super(c, SWT.BORDER); GridLayout gl = new GridLayout(); gl.numColumns = 3;/*from ww w. j av a2 s .co m*/ this.setLayout(gl); final Label l1 = new Label(this, SWT.BORDER); l1.setText("Column One"); final Label l2 = new Label(this, SWT.BORDER); l2.setText("Column Two"); final Label l3 = new Label(this, SWT.BORDER); l3.setText("Column Three"); final Text t1 = new Text(this, SWT.SINGLE | SWT.BORDER); final Text t2 = new Text(this, SWT.SINGLE | SWT.BORDER); final Text t3 = new Text(this, SWT.SINGLE | SWT.BORDER); final Text t4 = new Text(this, SWT.SINGLE | SWT.BORDER); final Text t5 = new Text(this, SWT.SINGLE | SWT.BORDER); final Text t6 = new Text(this, SWT.SINGLE | SWT.BORDER); GridData gd = new GridData(); gd.horizontalAlignment = GridData.CENTER; l1.setLayoutData(gd); gd = new GridData(); gd.horizontalAlignment = GridData.CENTER; l2.setLayoutData(gd); gd = new GridData(); gd.horizontalAlignment = GridData.CENTER; l3.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); t1.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); t2.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); t3.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); t4.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); t5.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); t6.setLayoutData(gd); }