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.InterpolationTab.java
@Override public void createControlPanel(Composite parent) { Composite comp;//from w w w .ja v a 2 s .co m GridLayout gridLayout = new GridLayout(2, false); // create drop down combo comp = new Composite(parent, SWT.NONE); comp.setLayout(gridLayout); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Image")); //$NON-NLS-1$ imageCb = new Combo(comp, SWT.DROP_DOWN); imageCb.add(GraphicsExample.getResourceString("House")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Question")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Task")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Font")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Cube")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("SWT")); //$NON-NLS-1$ imageCb.add(GraphicsExample.getResourceString("Ovals")); //$NON-NLS-1$ imageCb.select(0); imageCb.addListener(SWT.Selection, event -> example.redraw()); }
From source file:MainClass.java
public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, true)); new Label(composite, SWT.LEFT).setText("Do you have complaints?"); Composite yesNo = new Composite(composite, SWT.NONE); yesNo.setLayout(new FillLayout(SWT.VERTICAL)); yes = new Button(yesNo, SWT.RADIO); yes.setText("Yes"); no = new Button(yesNo, SWT.RADIO); no.setText("No"); setControl(composite);// www .ja v a 2 s. co m }
From source file:org.eclipse.swt.snippets.Snippet319.java
public void go() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 319"); shell.setBounds(10, 10, 600, 200);/*from w w w .j a v a 2 s . c om*/ /* Create SWT controls and add drag source */ final Label swtLabel = new Label(shell, SWT.BORDER); swtLabel.setBounds(10, 10, 580, 50); swtLabel.setText("SWT drag source"); DragSource dragSource = new DragSource(swtLabel, DND.DROP_COPY); dragSource.setTransfer(new MyTypeTransfer()); dragSource.addDragListener(new DragSourceAdapter() { @Override public void dragSetData(DragSourceEvent event) { MyType object = new MyType(); object.name = "content dragged from SWT"; object.time = System.currentTimeMillis(); event.data = object; } }); /* Create AWT/Swing controls */ Composite embeddedComposite = new Composite(shell, SWT.EMBEDDED); embeddedComposite.setBounds(10, 100, 580, 50); embeddedComposite.setLayout(new FillLayout()); Frame frame = SWT_AWT.new_Frame(embeddedComposite); final JLabel jLabel = new JLabel("AWT/Swing drop target"); frame.add(jLabel); /* Register the custom data flavour */ final DataFlavor flavor = new DataFlavor(MIME_TYPE, "MyType custom flavor"); /* * Note that according to jre/lib/flavormap.properties, the preferred way to * augment the default system flavor map is to specify the AWT.DnD.flavorMapFileURL * property in an awt.properties file. * * This snippet uses the alternate approach below in order to provide a simple * stand-alone snippet that demonstrates the functionality. This implementation * works well, but if the instanceof check below fails for some reason when used * in a different context then the drop will not be accepted. */ FlavorMap map = SystemFlavorMap.getDefaultFlavorMap(); if (map instanceof SystemFlavorMap) { SystemFlavorMap systemMap = (SystemFlavorMap) map; systemMap.addFlavorForUnencodedNative(MIME_TYPE, flavor); } /* add drop target */ DropTargetListener dropTargetListener = new DropTargetAdapter() { @Override public void drop(DropTargetDropEvent dropTargetDropEvent) { try { dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY); ByteArrayInputStream inStream = (ByteArrayInputStream) dropTargetDropEvent.getTransferable() .getTransferData(flavor); int available = inStream.available(); byte[] bytes = new byte[available]; inStream.read(bytes); MyType object = restoreFromByteArray(bytes); String string = object.name + ": " + new Date(object.time).toString(); jLabel.setText(string); } catch (Exception e) { e.printStackTrace(); } } }; new DropTarget(jLabel, dropTargetListener); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Survey.java
/** * Creates the page controls//from ww w.jav a2s .c o m */ public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, true)); new Label(composite, SWT.LEFT).setText("Do you have complaints?"); Composite yesNo = new Composite(composite, SWT.NONE); yesNo.setLayout(new FillLayout(SWT.VERTICAL)); yes = new Button(yesNo, SWT.RADIO); yes.setText("Yes"); no = new Button(yesNo, SWT.RADIO); no.setText("No"); setControl(composite); }
From source file:ControlSizeLocation.java
private void init() { GridLayout gridLayout = new GridLayout(2, true); shell.setLayout(gridLayout);//from w w w . j a v a 2 s . c om 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:org.eclipse.swt.examples.graphics.LineStyleTab.java
@Override public void createControlPanel(Composite parent) { Composite comp;/*from w ww. j a va2s .co m*/ comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineWidth")); //$NON-NLS-1$ lineWidthSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); lineWidthSpinner.setSelection(10); lineWidthSpinner.setMinimum(1); lineWidthSpinner.setMaximum(30); lineWidthSpinner.addListener(SWT.Selection, event -> example.redraw()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { lineColor = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the foreground to the 5th item in the menu (blue) lineColor = (GraphicsBackground) menu.getItem(4).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(lineColor.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.SpiralTab.java
/** * This method creates a spinner for specifying the number of petals. The call to the * createControlPanel method in the super class create the controls that are * defined in the super class.// w w w .j ava 2 s . c om * * @param parent The parent composite */ @Override public void createControlPanel(Composite parent) { super.createControlPanel(parent); // create spinner number of petals Composite comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout(2, false)); new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Petals")); //$NON-NLS-1$ petalSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); petalSpinner.setSelection(8); petalSpinner.setMinimum(3); petalSpinner.setMaximum(20); petalSpinner.addListener(SWT.Selection, event -> example.redraw()); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { foreground = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the foreground to the 2nd item in the menu foreground = (GraphicsBackground) menu.getItem(1).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(foreground.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.LineJoinTab.java
@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("LineJoin")); //$NON-NLS-1$ joinCb = new Combo(comp, SWT.DROP_DOWN); joinCb.add(GraphicsExample.getResourceString("bevel")); //$NON-NLS-1$ joinCb.add(GraphicsExample.getResourceString("miter")); //$NON-NLS-1$ joinCb.add(GraphicsExample.getResourceString("round")); //$NON-NLS-1$ joinCb.select(1);//from w ww. j ava2s.com joinCb.addListener(SWT.Selection, event -> example.redraw()); // color menu ColorMenu cm = new ColorMenu(); cm.setPatternItems(example.checkAdvancedGraphics()); menu = cm.createMenu(parent.getParent(), gb -> { shapeColor = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // initialize the shape color to the 4th item in the menu (green) shapeColor = (GraphicsBackground) menu.getItem(3).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(shapeColor.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.GraphicAntialiasTab.java
@Override public void createControlPanel(Composite parent) { Composite comp;//from w ww . ja va 2 s . c om // 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 -> { ovalColorGB = gb; colorButton.setImage(gb.getThumbNail()); example.redraw(); }); // create color button comp = new Composite(parent, SWT.NONE); comp.setLayout(new GridLayout()); // initialize the background to the 5th item in the menu (blue) ovalColorGB = (GraphicsBackground) menu.getItem(4).getData(); // color button colorButton = new Button(comp, SWT.PUSH); colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$ colorButton.setImage(ovalColorGB.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:SWTBrowser.java
public SWTBrowser() { shell.setLayout(new GridLayout()); ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT); final ToolBarManager manager = new ToolBarManager(toolBar); Composite compositeLocation = new Composite(shell, SWT.NULL); compositeLocation.setLayout(new GridLayout(3, false)); compositeLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label labelAddress = new Label(compositeLocation, SWT.NULL); labelAddress.setText("Address"); textLocation = new Text(compositeLocation, SWT.SINGLE | SWT.BORDER); textLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button buttonGo = new Button(compositeLocation, SWT.NULL); buttonGo.setImage(new Image(shell.getDisplay(), "java2s.gif")); browser = new Browser(shell, SWT.BORDER); browser.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite compositeStatus = new Composite(shell, SWT.NULL); compositeStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); compositeStatus.setLayout(new GridLayout(2, false)); labelStatus = new Label(compositeStatus, SWT.NULL); labelStatus.setText("Ready"); labelStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final ProgressBar progressBar = new ProgressBar(compositeStatus, SWT.SMOOTH); Listener openURLListener = new Listener() { public void handleEvent(Event event) { browser.setUrl(textLocation.getText()); }/*from w w w . j a v a 2s. c om*/ }; buttonGo.addListener(SWT.Selection, openURLListener); textLocation.addListener(SWT.DefaultSelection, openURLListener); // Adds tool bar items using actions. final Action actionBackward = new Action("&Backword", ImageDescriptor.createFromFile(null, "java2s.gif")) { public void run() { browser.back(); } }; actionBackward.setEnabled(false); // action is disabled at start up. final Action actionForward = new Action("&Forward", ImageDescriptor.createFromFile(null, "icons/web/forward.gif")) { public void run() { browser.forward(); } }; actionForward.setEnabled(false); // action is disabled at start up. Action actionStop = new Action("&Stop", ImageDescriptor.createFromFile(null, "icons/web/stop.gif")) { public void run() { browser.stop(); } }; Action actionRefresh = new Action("&Refresh", ImageDescriptor.createFromFile(null, "icons/web/refresh.gif")) { public void run() { browser.refresh(); } }; Action actionHome = new Action("&Home", ImageDescriptor.createFromFile(null, "icons/web/home.gif")) { public void run() { browser.setUrl("http://www.eclipse.org"); } }; manager.add(actionBackward); manager.add(actionForward); manager.add(actionStop); manager.add(actionRefresh); manager.add(actionHome); manager.update(true); toolBar.pack(); browser.addLocationListener(new LocationListener() { public void changing(LocationEvent event) { // Displays the new location in the text field. textLocation.setText(event.location); } public void changed(LocationEvent event) { // Update tool bar items. actionBackward.setEnabled(browser.isBackEnabled()); actionForward.setEnabled(browser.isForwardEnabled()); manager.update(false); } }); browser.addProgressListener(new ProgressListener() { public void changed(ProgressEvent event) { progressBar.setMaximum(event.total); progressBar.setSelection(event.current); } public void completed(ProgressEvent event) { progressBar.setSelection(0); } }); browser.addStatusTextListener(new StatusTextListener() { public void changed(StatusTextEvent event) { labelStatus.setText(event.text); } }); browser.addTitleListener(new TitleListener() { public void changed(TitleEvent event) { shell.setText(event.title + " - powered by SWT"); } }); initialize(display, browser); shell.setSize(500, 400); shell.open(); //textUser.forceFocus(); //browser.setText( // "<html><body>" + "<h1>SWT & JFace </h1>" + "</body/html>"); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }