List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:org.eclipse.swt.examples.graphics.TextAntialiasTab.java
@Override public void createControlPanel(Composite parent) { Composite comp;// www .j av a2 s .com // create drop down combo for antialiasing comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$ aliasCombo = new Combo(comp, SWT.DROP_DOWN); aliasCombo.add("OFF"); aliasCombo.add("DEFAULT"); aliasCombo.add("ON"); aliasCombo.select(0); aliasCombo.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setColorItems(true); menu = cm.createMenu(parent.getParent(), gb -> { textColor = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the color to black textColor = (GraphicsBackground) menu.getItem(1).getData(); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(textColor.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.graphics.PathClippingTab.java
/** * Creates the widgets used to control the drawing. */// ww w. jav a2 s.c o m @Override public void createControlPanel(Composite parent) { // create drop down combo for choosing clipping Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Clipping")); //$NON-NLS-1$ clippingCb = new Combo(comp, SWT.DROP_DOWN); clippingCb.add(GraphicsExample.getResourceString("Circles")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Rectangle")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Oval")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Word")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Star")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Triangles")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Default")); //$NON-NLS-1$ clippingCb.select(0); clippingCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { background = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the background to the 5th item in the menu (blue) background = (GraphicsBackground) menu.getItem(4).getData(); // color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.graphics.RegionClippingTab.java
/** * Creates the widgets used to control the drawing. *//*from w w w . j a v a 2 s . c om*/ @Override public void createControlPanel(Composite parent) { // create drop down combo for choosing clipping Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Clipping")); //$NON-NLS-1$ clippingCb = new Combo(comp, SWT.DROP_DOWN); clippingCb.add(GraphicsExample.getResourceString("Region1")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Region2")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Add")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Sub")); //$NON-NLS-1$ clippingCb.add(GraphicsExample.getResourceString("Inter")); //$NON-NLS-1$ clippingCb.select(0); clippingCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); menu1 = cm.createMenu(parent.getParent(), gb -> { colorGB1 = gb; colorButton1.setImage(gb.getThumbNail()); example.redraw(); }); menu2 = cm.createMenu(parent.getParent(), gb -> { colorGB2 = gb; colorButton2.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the color to blue colorGB1 = (GraphicsBackground) menu1.getItem(4).getData(); // initialize the color to red colorGB2 = (GraphicsBackground) menu2.getItem(2).getData(); // color button 1 comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton1 = new Button(comp, SWT.PUSH); colorButton1.setText(GraphicsExample.getResourceString("Color1")); //$NON-NLS-1$ colorButton1.setImage(colorGB1.getThumbNail()); colorButton1.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu1.setLocation(point.x, point.y + bounds.height); menu1.setVisible(true); }); // color button 2 comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton2 = new Button(comp, SWT.PUSH); colorButton2.setText(GraphicsExample.getResourceString("Color2")); //$NON-NLS-1$ colorButton2.setImage(colorGB2.getThumbNail()); colorButton2.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu2.setLocation(point.x, point.y + bounds.height); menu2.setVisible(true); }); }
From source file:org.eclipse.swt.examples.graphics.CustomAlphaTab.java
/** * Creates the widgets used to control the drawing. */// ww w.j a v a 2 s. co m @Override public void createControlPanel(Composite parent) { super.createControlPanel(parent); // create drop down combo for choosing clipping Composite comp; // create spinner for line width comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Alpha")); //$NON-NLS-1$ alphaSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); alphaSpinner.setMinimum(0); alphaSpinner.setMaximum(255); alphaSpinner.setSelection(127); alphaSpinner.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { background = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the background to the 5th item in the menu (blue) background = (GraphicsBackground) menu.getItem(4).getData(); // color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(background.getThumbNail()); colorButton.addListener(SWT.Selection, event -> { final Button button = (Button) event.widget; final Composite parent1 = button.getParent(); Rectangle bounds = button.getBounds(); Point point = parent1.toDisplay(new Point(bounds.x, bounds.y)); menu.setLocation(point.x, point.y + bounds.height); menu.setVisible(true); }); }
From source file:org.eclipse.swt.examples.addressbook.SearchDialog.java
/** * Class constructor that sets the parent shell and the table widget that * the dialog will search./*from ww w. ja va 2s. c o m*/ * * @param parent Shell * The shell that is the parent of the dialog. */ public SearchDialog(Shell parent) { shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE); GridLayout layout = new GridLayout(); layout.numColumns = 2; shell.setLayout(layout); shell.setText(resAddressBook.getString("Search_dialog_title")); shell.addShellListener(ShellListener.shellClosedAdapter(e -> { // don't dispose of the shell, just hide it for later use e.doit = false; shell.setVisible(false); })); Label label = new Label(shell, SWT.LEFT); label.setText(resAddressBook.getString("Dialog_find_what")); searchText = new Text(shell, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchText.setLayoutData(gridData); searchText.addModifyListener(e -> { boolean enableFind = (searchText.getCharCount() != 0); findButton.setEnabled(enableFind); }); searchAreaLabel = new Label(shell, SWT.LEFT); searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchArea.setLayoutData(gridData); matchCase = new Button(shell, SWT.CHECK); matchCase.setText(resAddressBook.getString("Dialog_match_case")); gridData = new GridData(); gridData.horizontalSpan = 2; matchCase.setLayoutData(gridData); matchWord = new Button(shell, SWT.CHECK); matchWord.setText(resAddressBook.getString("Dialog_match_word")); gridData = new GridData(); gridData.horizontalSpan = 2; matchWord.setLayoutData(gridData); Group direction = new Group(shell, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; direction.setLayoutData(gridData); direction.setLayout(new FillLayout()); direction.setText(resAddressBook.getString("Dialog_direction")); Button up = new Button(direction, SWT.RADIO); up.setText(resAddressBook.getString("Dialog_dir_up")); up.setSelection(false); down = new Button(direction, SWT.RADIO); down.setText(resAddressBook.getString("Dialog_dir_down")); down.setSelection(true); Composite composite = new Composite(shell, SWT.NONE); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 2; composite.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = true; composite.setLayout(layout); findButton = new Button(composite, SWT.PUSH); findButton.setText(resAddressBook.getString("Dialog_find")); findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); findButton.setEnabled(false); findButton.addSelectionListener(widgetSelectedAdapter(e -> { if (!findHandler.find()) { MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL); box.setText(shell.getText()); box.setMessage(resAddressBook.getString("Cannot_find") + "\"" + searchText.getText() + "\""); box.open(); } })); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText(resAddressBook.getString("Cancel")); cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); cancelButton.addSelectionListener(widgetSelectedAdapter(e -> shell.setVisible(false))); shell.pack(); }
From source file:org.eclipse.swt.examples.graphics.ImageTransformTab.java
/** * This method creates the controls specific to the tab. The call to the * createControlPanel method in the super class create the controls that are * defined in the super class.//from ww w. j a v a 2 s. c o m * * @param parent The parent composite */ @Override public void createControlPanel(Composite parent) { Composite comp; GridLayout gridLayout = new GridLayout(2, false); // create spinner for the rotation angle comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Rotate")); //$NON-NLS-1$ rotateSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); GC gc = new GC(rotateSpinner); int width = (int) (gc.getFontMetrics().getAverageCharacterWidth() * 5); gc.dispose(); rotateSpinner.setLayoutData(new GridData(width, SWT.DEFAULT)); rotateSpinner.setSelection(0); rotateSpinner.setMinimum(-720); rotateSpinner.setMaximum(720); rotateSpinner.setIncrement(30); rotateSpinner.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for translating along the x axis comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("xtranslate")); //$NON-NLS-1$ translateSpinnerX = new Spinner(comp, SWT.BORDER | SWT.WRAP); translateSpinnerX.setLayoutData(new GridData(width, SWT.DEFAULT)); translateSpinnerX.setMinimum(-100); translateSpinnerX.setMaximum(500); translateSpinnerX.setSelection(0); translateSpinnerX.setIncrement(10); translateSpinnerX.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for translating along the y axis comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("ytranslate")); //$NON-NLS-1$ translateSpinnerY = new Spinner(comp, SWT.BORDER | SWT.WRAP); translateSpinnerY.setLayoutData(new GridData(width, SWT.DEFAULT)); translateSpinnerY.setMinimum(-100); translateSpinnerY.setMaximum(500); translateSpinnerY.setSelection(0); translateSpinnerY.setIncrement(10); translateSpinnerY.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for scaling along the x axis comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("xscale")); //$NON-NLS-1$ scaleSpinnerX = new Spinner(comp, SWT.BORDER | SWT.WRAP); scaleSpinnerX.setLayoutData(new GridData(width, SWT.DEFAULT)); scaleSpinnerX.setDigits(2); scaleSpinnerX.setMinimum(1); scaleSpinnerX.setMaximum(400); scaleSpinnerX.setSelection(100); scaleSpinnerX.setIncrement(10); scaleSpinnerX.addListener(SWT.Selection, event -> example.redraw()); // create a spinner for scaling along the y axis comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("yscale")); //$NON-NLS-1$ scaleSpinnerY = new Spinner(comp, SWT.BORDER | SWT.WRAP); scaleSpinnerY.setLayoutData(new GridData(width, SWT.DEFAULT)); scaleSpinnerY.setDigits(2); scaleSpinnerY.setMinimum(1); scaleSpinnerY.setMaximum(400); scaleSpinnerY.setSelection(100); scaleSpinnerY.setIncrement(10); scaleSpinnerY.addListener(SWT.Selection, event -> example.redraw()); // create a button for inverting the transform matrix comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); invertButton = new Button(comp, SWT.TOGGLE); invertButton.setText(GraphicsExample.getResourceString("Invert")); //$NON-NLS-1$ invertButton.addListener(SWT.Selection, event -> example.redraw()); }
From source file:MainClass.java
public void createLabel(Composite c, int style, String text) { Label l = new Label(c, style); l.setText(text); }
From source file:SendMessage.java
/** * Creates the main window's contents//w w w . j a v a 2 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(5, true)); // Create a big text box for the message text final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 5; text.setLayoutData(data); // Create the Confirm button Button confirm = new Button(composite, SWT.PUSH); confirm.setText("Confirm"); confirm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Error button Button error = new Button(composite, SWT.PUSH); error.setText("Error"); error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Information button Button information = new Button(composite, SWT.PUSH); information.setText("Information"); information.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Question button Button question = new Button(composite, SWT.PUSH); question.setText("Question"); question.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the Warning button Button warning = new Button(composite, SWT.PUSH); warning.setText("Warning"); warning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label to display the return value final Label label = new Label(composite, SWT.NONE); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 5; label.setLayoutData(data); // Save ourselves some typing final Shell shell = parent.getShell(); // Display a Confirmation dialog confirm.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean b = MessageDialog.openConfirm(shell, "Confirm", text.getText()); label.setText("Returned " + Boolean.toString(b)); } }); // Display an Error dialog error.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openError(shell, "Error", text.getText()); label.setText("Returned void"); } }); // Display an Information dialog information.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openInformation(shell, "Information", text.getText()); label.setText("Returned void"); } }); // Display a Question dialog question.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { boolean b = MessageDialog.openQuestion(shell, "Question", text.getText()); label.setText("Returned " + Boolean.toString(b)); } }); // Display a Warning dialog warning.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { MessageDialog.openWarning(shell, "Warning", text.getText()); label.setText("Returned void"); } }); return composite; }
From source file:SWTBrowserDemo.java
public SWTBrowserDemo(Composite parent, boolean top) { this.parent = parent; try {/*from w ww . j a va 2s . co m*/ browser = new Browser(parent, SWT.BORDER); } catch (SWTError e) { error = e; /* Browser widget could not be instantiated */ parent.setLayout(new FillLayout()); Label label = new Label(parent, SWT.CENTER | SWT.WRAP); label.setText(getResourceString("BrowserNotCreated")); parent.layout(true); return; } initResources(); final Display display = parent.getDisplay(); browser.setData("org.eclipse.swt.examples.browserexample.BrowserApplication", this); browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { Shell shell = new Shell(display); if (icon != null) shell.setImage(icon); shell.setLayout(new FillLayout()); SWTBrowserDemo app = new SWTBrowserDemo(shell, false); app.setShellDecoration(icon, true); event.browser = app.getBrowser(); } }); if (top) { browser.setUrl(getResourceString("Startup")); show(false, null, null, true, true, true, true); } else { browser.addVisibilityWindowListener(new VisibilityWindowListener() { public void hide(WindowEvent e) { } public void show(WindowEvent e) { Browser browser = (Browser) e.widget; SWTBrowserDemo app = (SWTBrowserDemo) browser .getData("org.eclipse.swt.examples.browserexample.BrowserApplication"); app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar); } }); browser.addCloseWindowListener(new CloseWindowListener() { public void close(WindowEvent event) { Browser browser = (Browser) event.widget; Shell shell = browser.getShell(); shell.close(); } }); } }
From source file:org.eclipse.swt.examples.graphics.CountDownTab.java
/** * This method creates the controls specific to the tab. The call to the * createControlPanel method in the super class create the controls that are * defined in the super class./* ww w . j av a 2s.com*/ * * @param parent * The parent composite */ @Override public void createControlPanel(Composite parent) { super.createControlPanel(parent); if (nextNumber < 1) nextNumber = startNumber; // add selection listener to reset nextNumber after // the sequence has completed playItem.addListener(SWT.Selection, event -> { if (nextNumber < 1) nextNumber = startNumber; }); Composite comp; GridLayout gridLayout = new GridLayout(2, false); // create spinner for line width comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineWidth")); //$NON-NLS-1$ lineWidthSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); lineWidthSpinner.setSelection(20); lineWidthSpinner.setMinimum(1); lineWidthSpinner.setMaximum(100); lineWidthSpinner.addListener(SWT.Selection, event -> { if (!pauseItem.isEnabled()) { example.redraw(); } }); // create drop down combo for antialiasing comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$ aliasCombo = new Combo(comp, SWT.DROP_DOWN); aliasCombo.add("DEFAULT"); aliasCombo.add("OFF"); aliasCombo.add("ON"); aliasCombo.select(0); antialias = aliasValues[0]; aliasCombo.addListener(SWT.Selection, event -> { antialias = aliasValues[aliasCombo.getSelectionIndex()]; if (!pauseItem.isEnabled()) { example.redraw(); } }); // create drop down combo for line cap comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineCap")); //$NON-NLS-1$ lineCapCombo = new Combo(comp, SWT.DROP_DOWN); lineCapCombo.add("FLAT"); lineCapCombo.add("SQUARE"); lineCapCombo.add("ROUND"); lineCapCombo.select(0); lineCap = capValues[0]; lineCapCombo.addListener(SWT.Selection, event -> { lineCap = capValues[lineCapCombo.getSelectionIndex()]; if (!pauseItem.isEnabled()) { example.redraw(); } }); }