List of usage examples for org.eclipse.swt.widgets Label setText
public void setText(String text)
From source file:Menus.java
/** * Creates the No Radio Group pop-up menu * /*w ww .ja v a 2s. c o m*/ * @param shell the main window */ private void createNoRadioGroupPopUpMenu(Shell shell) { // Create a composite that the pop-up menu will be // associated with Label label = new Label(shell, SWT.BORDER); label.setText("No Radio Group Menu"); // Create the pop-up menu with the No Radio Group style Menu menu = new Menu(shell, SWT.POP_UP | SWT.NO_RADIO_GROUP); label.setMenu(menu); // Create all the items in the pop-up menu MenuItem item1 = new MenuItem(menu, SWT.RADIO); item1.setText("Radio One"); MenuItem item2 = new MenuItem(menu, SWT.RADIO); item2.setText("Radio Two"); MenuItem item3 = new MenuItem(menu, SWT.RADIO); item3.setText("Radio Three"); // Set the pop-up menu as the pop-up for the label label.setMenu(menu); }
From source file:Ch11WizardComposite.java
public void createControl(Composite parent) { Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout(2, false)); Label l = new Label(topLevel, SWT.CENTER); l.setText("Use default directory?"); button = new Button(topLevel, SWT.CHECK); setControl(topLevel);/* w w w . j a va2s.com*/ setPageComplete(true); }
From source file:Ch11WizardComposite.java
public void createControl(Composite parent) { Composite topLevel = new Composite(parent, SWT.NONE); topLevel.setLayout(new GridLayout(2, false)); Label l = new Label(topLevel, SWT.CENTER); l.setText("Enter the directory to use:"); text = new Text(topLevel, SWT.SINGLE); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); setControl(topLevel);//from www. jav a 2 s. c o m setPageComplete(true); }
From source file:ControlSizeLocation.java
private void init() { GridLayout gridLayout = new GridLayout(2, true); shell.setLayout(gridLayout);//w w w .j av a 2 s . c o m Composite left = new Composite(shell, SWT.NULL); left.setLayout(new GridLayout()); //left.setLayout(new FillLayout()); left.setLayoutData(new GridData(GridData.FILL_BOTH)); left.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); button = new Button(left, SWT.PUSH); button.setText("Button"); button.setLayoutData(new GridData()); Composite right = new Composite(shell, SWT.NULL); right.setLayout(new GridLayout(4, true)); right.setLayoutData(new GridData(GridData.FILL_BOTH)); Label label = new Label(right, SWT.NULL); label.setText("X"); label = new Label(right, SWT.NULL); label.setText("Y"); label = new Label(right, SWT.NULL); label.setText("Width"); label = new Label(right, SWT.NULL); label.setText("Height"); x = new Text(right, SWT.BORDER); y = new Text(right, SWT.BORDER); w = new Text(right, SWT.BORDER); h = new Text(right, SWT.BORDER); SelectionListener selectionListener = new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b == get) { System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); } else if (b == set) { int vx = getNumber(x); int vy = getNumber(y); int vw = getNumber(w); int vh = getNumber(h); if (vx != -1 && vy != -1) { if (vw != -1 && vh != -1) { Rectangle rectangle = new Rectangle(vx, vy, vw, vh); button.setBounds(rectangle); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setBounds: " + rectangle); } else { Point point = new Point(vx, vy); button.setLocation(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setLocation: " + point); } } else if (vw != -1 && vh != -1) { Point point = new Point(vw, vh); button.setSize(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setSize: " + point); } } } public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }; get = new Button(right, SWT.PUSH); get.setText("Get"); get.addSelectionListener(selectionListener); set = new Button(right, SWT.PUSH); set.setText("Set"); set.addSelectionListener(selectionListener); }
From source file:Sample.java
public Sample() { shell.setText("Book Entry Demo"); GridLayout gridLayout = new GridLayout(4, false); gridLayout.verticalSpacing = 8;/*from w w w . java2s . c o m*/ shell.setLayout(gridLayout); // Title 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); // Author(s) 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); // Cover 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); // Details. 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 pubisher = new Text(shell, SWT.SINGLE | SWT.BORDER); pubisher.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"); // Abstract. 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. Button enter = new Button(shell, SWT.PUSH); enter.setText("Enter"); gridData = new GridData(); gridData.horizontalSpan = 4; gridData.horizontalAlignment = GridData.END; enter.setLayoutData(gridData); // Fill information. title.setText("Professional Java Interfaces with SWT/JFace"); authors.setText("Jack Li Guojie"); pages.setText("500pp"); pubisher.setText("John Wiley & Sons"); cover.setBackground(new Image(display, "java2s.gif")); bookAbstract.setText("This book provides a comprehensive guide for \n" + "you to create Java user interfaces with SWT/JFace. "); shell.pack(); shell.open(); // 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:org.eclipse.swt.examples.addressbook.DataEntryDialog.java
private void createTextWidgets() { if (labels == null) return;//from www . j a v a 2s . co m Composite composite = new Composite(shell, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); layout.numColumns = 2; composite.setLayout(layout); if (values == null) values = new String[labels.length]; for (int i = 0; i < labels.length; i++) { Label label = new Label(composite, SWT.RIGHT); label.setText(labels[i]); Text text = new Text(composite, SWT.BORDER); GridData gridData = new GridData(); gridData.widthHint = 400; text.setLayoutData(gridData); if (values[i] != null) { text.setText(values[i]); } text.setData("index", Integer.valueOf(i)); addTextListener(text); } }
From source file:MainClass.java
public void createContents(Shell shell, String location) { shell.setLayout(new FormLayout()); Composite controls = new Composite(shell, SWT.NONE); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); controls.setLayoutData(data);/* w w w. j a va2s . c o m*/ Label status = new Label(shell, SWT.NONE); data = new FormData(); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); status.setLayoutData(data); final Browser browser = new Browser(shell, SWT.BORDER); data = new FormData(); data.top = new FormAttachment(controls); data.bottom = new FormAttachment(status); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); browser.setLayoutData(data); controls.setLayout(new GridLayout(7, false)); Button button = new Button(controls, SWT.PUSH); button.setText("Back"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.back(); } }); button = new Button(controls, SWT.PUSH); button.setText("Forward"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.forward(); } }); button = new Button(controls, SWT.PUSH); button.setText("Refresh"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.refresh(); } }); button = new Button(controls, SWT.PUSH); button.setText("Stop"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.stop(); } }); final Text url = new Text(controls, SWT.BORDER); url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); url.setFocus(); button = new Button(controls, SWT.PUSH); button.setText("Go"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { browser.setUrl(url.getText()); } }); Label throbber = new Label(controls, SWT.NONE); throbber.setText(AT_REST); shell.setDefaultButton(button); browser.addCloseWindowListener(new AdvancedCloseWindowListener()); browser.addLocationListener(new AdvancedLocationListener(url)); browser.addProgressListener(new AdvancedProgressListener(throbber)); browser.addStatusTextListener(new AdvancedStatusTextListener(status)); if (location != null) { browser.setUrl(location); } }
From source file:org.eclipse.swt.examples.graphics.AnimatedGraphicsTab.java
/** * Creates the toolbar controls: play, pause and animation timer. * * @param parent A composite// ww w . j a va 2 s . co m */ void createToolBar(final Composite parent) { final Display display = parent.getDisplay(); toolBar = new ToolBar(parent, SWT.FLAT); Listener toolBarListener = event -> { switch (event.type) { case SWT.Selection: { if (event.widget == playItem) { animate = true; playItem.setEnabled(!animate); pauseItem.setEnabled(animate); } else if (event.widget == pauseItem) { animate = false; playItem.setEnabled(!animate); pauseItem.setEnabled(animate); } } break; } }; // play tool item playItem = new ToolItem(toolBar, SWT.PUSH); playItem.setText(GraphicsExample.getResourceString("Play")); //$NON-NLS-1$ playItem.setImage(example.loadImage(display, "play.gif")); //$NON-NLS-1$ playItem.addListener(SWT.Selection, toolBarListener); // pause tool item pauseItem = new ToolItem(toolBar, SWT.PUSH); pauseItem.setText(GraphicsExample.getResourceString("Pause")); //$NON-NLS-1$ pauseItem.setImage(example.loadImage(display, "pause.gif")); //$NON-NLS-1$ pauseItem.addListener(SWT.Selection, toolBarListener); // timer spinner Composite comp = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(2, false); comp.setLayout(gridLayout); Label label = new Label(comp, SWT.CENTER); label.setText(GraphicsExample.getResourceString("Animation")); //$NON-NLS-1$ timerSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); timerSpinner.setMaximum(1000); playItem.setEnabled(false); animate = true; timerSpinner.setSelection(getInitialAnimationTime()); }
From source file:org.eclipse.swt.examples.paint.TextTool.java
/** * Handles a mouseDown event./* w w w . j a va 2 s.co m*/ * * @param event the mouse event detail information */ @Override public void mouseDown(MouseEvent event) { if (event.button == 1) { // draw with left mouse button getPaintSurface().commitRubberbandSelection(); } else { // set text with right mouse button getPaintSurface().clearRubberbandSelection(); Shell shell = getPaintSurface().getShell(); final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText(PaintExample.getResourceString("tool.Text.dialog.title")); dialog.setLayout(new GridLayout()); Label label = new Label(dialog, SWT.NONE); label.setText(PaintExample.getResourceString("tool.Text.dialog.message")); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); final Text field = new Text(dialog, SWT.SINGLE | SWT.BORDER); field.setText(drawText); field.selectAll(); field.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Composite buttons = new Composite(dialog, SWT.NONE); GridLayout layout = new GridLayout(2, true); layout.marginWidth = 0; buttons.setLayout(layout); buttons.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); Button ok = new Button(buttons, SWT.PUSH); ok.setText(PaintExample.getResourceString("OK")); ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); ok.addSelectionListener(widgetSelectedAdapter(e -> { drawText = field.getText(); dialog.dispose(); })); Button cancel = new Button(buttons, SWT.PUSH); cancel.setText(PaintExample.getResourceString("Cancel")); cancel.addSelectionListener(widgetSelectedAdapter(e -> dialog.dispose())); dialog.setDefaultButton(ok); dialog.pack(); dialog.open(); Display display = dialog.getDisplay(); while (!shell.isDisposed() && !dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }
From source file:SWTTextEditor.java
public void open() { Shell parent = getParent();/* w w w . ja v a 2 s. c o m*/ final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setSize(200, 100); dialog.setText("About"); final Label l = new Label(dialog, SWT.NONE); l.setText("An SWT Text Editor"); l.setBounds(43, 20, 100, 20); Button b = new Button(dialog, SWT.PUSH | SWT.BORDER); b.setText("OK"); b.setBounds(80, 45, 40, 25); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { dialog.dispose(); } }); dialog.open(); Display display = parent.getDisplay(); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }