Example usage for org.eclipse.swt.widgets Label Label

List of usage examples for org.eclipse.swt.widgets Label Label

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Label Label.

Prototype

public Label(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:org.eclipse.swt.examples.controlexample.LabelTab.java

/**
 * Creates the "Example" widgets./*w  w  w .j  a  v a2  s  .c  o  m*/
 */
@Override
void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (wrapButton.getSelection())
        style |= SWT.WRAP;
    if (separatorButton.getSelection())
        style |= SWT.SEPARATOR;
    if (horizontalButton.getSelection())
        style |= SWT.HORIZONTAL;
    if (verticalButton.getSelection())
        style |= SWT.VERTICAL;
    if (shadowInButton.getSelection())
        style |= SWT.SHADOW_IN;
    if (shadowOutButton.getSelection())
        style |= SWT.SHADOW_OUT;
    if (shadowNoneButton.getSelection())
        style |= SWT.SHADOW_NONE;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (leftButton.getSelection())
        style |= SWT.LEFT;
    if (centerButton.getSelection())
        style |= SWT.CENTER;
    if (rightButton.getSelection())
        style |= SWT.RIGHT;

    /* Create the example widgets */
    label1 = new Label(textLabelGroup, style);
    label1.setText(ControlExample.getResourceString("One"));
    label2 = new Label(textLabelGroup, style);
    label2.setText(ControlExample.getResourceString("Two"));
    label3 = new Label(textLabelGroup, style);
    if (wrapButton.getSelection()) {
        label3.setText(ControlExample.getResourceString("Wrap_Text"));
    } else {
        label3.setText(ControlExample.getResourceString("Three"));
    }
    label4 = new Label(imageLabelGroup, style);
    label4.setImage(instance.images[ControlExample.ciClosedFolder]);
    label5 = new Label(imageLabelGroup, style);
    label5.setImage(instance.images[ControlExample.ciOpenFolder]);
    label6 = new Label(imageLabelGroup, style);
    label6.setImage(instance.images[ControlExample.ciTarget]);
}

From source file:grafici.PrenotazioneTimeSeriesChart.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * //from  w w  w  . j av  a2  s  . co m
 * @param title
 *            the frame title.
 */
public PrenotazioneTimeSeriesChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);

    Label titolo = new Label(this, SWT.NONE);
    titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD));
    titolo.setText(title);
    GridData gdLbl = new GridData(SWT.FILL);
    titolo.setLayoutData(gdLbl);
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));
    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}

From source file:DumbUser.java

/**
 * Creates the dialog area/*w  w  w  .  ja  v  a 2 s .  com*/
 * 
 * @param parent the parent composite
 * @return Control
 */
protected Control createDialogArea(Composite parent) {
    createMessageArea(parent);

    // Create a composite to hold the label
    Composite composite = new Composite(parent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    composite.setLayout(new FillLayout());

    // Create the label for the "hidden" message
    label = new Label(composite, SWT.LEFT);

    return composite;
}

From source file:BackupFiles.java

/**
 * Creates the main window's contents/*  w  w  w  .j  ava  2 s.  c om*/
 * 
 * @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 the source directory panel and its controls
    final Text sourceDir = createFilePanelHelper(composite, "Source Dir:");

    // Create the CheckboxTableViewer to display the files in the source dir
    final CheckboxTableViewer ctv = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    ctv.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    ctv.setContentProvider(new BackupFilesContentProvider());
    ctv.setLabelProvider(new BackupFilesLabelProvider());

    // Create the destination directory panel and its controls
    final Text destDir = createFilePanelHelper(composite, "Dest Dir:");

    // Create the Copy button
    Button copy = new Button(composite, SWT.PUSH);
    copy.setText("Copy");

    // Create the status field
    status = new Label(composite, SWT.NONE);
    status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // When the source directory changes, change the input for the viewer
    sourceDir.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            ctv.setInput(((Text) event.widget).getText());
        }
    });

    // When copy is pressed, copy the files
    copy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Get the checked elements
            Object[] files = ctv.getCheckedElements();
            if (files.length > 0) {
                // Some files are checked; make sure we have a valid
                // destination
                File dest = new File(destDir.getText());
                if (dest.isDirectory()) {
                    // Go through each file
                    for (int i = 0, n = files.length; i < n; i++) {
                        copyFile((File) files[i], dest);
                    }
                } else
                    showMessage("You must select a valid destination directory");
            } else
                showMessage("You must select some files to copy");
        }
    });

    return composite;
}

From source file:Menus.java

/**
 * Creates the left-half pop-up menu/* w  w  w.  ja va 2  s  .c o  m*/
 * 
 * @param shell the main window
 */
private void createPopUpMenu(Shell shell) {
    // Create a composite that the pop-up menu will be
    // associated with
    Label label = new Label(shell, SWT.BORDER);
    label.setText("Pop-up Menu");

    // Create the pop-up menu
    Menu menu = new Menu(label);

    // Create the images
    star = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif"));
    circle = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif"));
    square = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif"));
    triangle = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("java2s.gif"));

    // Create all the items in the pop-up menu
    MenuItem newItem = new MenuItem(menu, SWT.CASCADE);
    newItem.setText("New");
    newItem.setImage(star);
    MenuItem refreshItem = new MenuItem(menu, SWT.NONE);
    refreshItem.setText("Refresh");
    refreshItem.setImage(circle);
    MenuItem deleteItem = new MenuItem(menu, SWT.NONE);
    deleteItem.setText("Delete");

    new MenuItem(menu, SWT.SEPARATOR);

    // Add a check menu item and select it
    MenuItem checkItem = new MenuItem(menu, SWT.CHECK);
    checkItem.setText("Check");
    checkItem.setSelection(true);
    checkItem.setImage(square);

    // Add a push menu item
    MenuItem pushItem = new MenuItem(menu, SWT.PUSH);
    pushItem.setText("Push");

    new MenuItem(menu, SWT.SEPARATOR);

    // Create some radio items
    MenuItem item1 = new MenuItem(menu, SWT.RADIO);
    item1.setText("Radio One");
    item1.setImage(triangle);
    MenuItem item2 = new MenuItem(menu, SWT.RADIO);
    item2.setText("Radio Two");
    MenuItem item3 = new MenuItem(menu, SWT.RADIO);
    item3.setText("Radio Three");

    // Create a new radio group
    new MenuItem(menu, SWT.SEPARATOR);

    // Create some radio items
    MenuItem itema = new MenuItem(menu, SWT.RADIO);
    itema.setText("Radio A");
    MenuItem itemb = new MenuItem(menu, SWT.RADIO);
    itemb.setText("Radio B");
    MenuItem itemc = new MenuItem(menu, SWT.RADIO);
    itemc.setText("Radio C");

    // Create the New item's dropdown menu
    Menu newMenu = new Menu(menu);
    newItem.setMenu(newMenu);

    // Create the items in the New dropdown menu
    MenuItem shortcutItem = new MenuItem(newMenu, SWT.NONE);
    shortcutItem.setText("Shortcut");
    MenuItem iconItem = new MenuItem(newMenu, SWT.NONE);
    iconItem.setText("Icon");

    // Set the pop-up menu as the pop-up for the label
    label.setMenu(menu);
}

From source file:org.eclipse.swt.examples.graphics.AnimatedGraphicsTab.java

/**
 * Creates the toolbar controls: play, pause and animation timer.
 *
 * @param parent A composite/*from  w w  w.j  av a 2s  . c om*/
 */
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:ToolBarComplex.java

/**
 * Creates the window contents//from   w w w  .  j  a v a  2  s . c o  m
 * 
 * @param shell the parent shell
 */
private void createContents(Shell shell) {
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    createToolbar(shell);

    // Create the labels to display the statuses of
    // the "check" and "radio" buttons
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    new Label(composite, SWT.RIGHT).setText("Check One Status:");
    checkOneStatus = new Label(composite, SWT.LEFT);
    checkOneStatus.setText("Off");

    new Label(composite, SWT.RIGHT).setText("Check Two Status:");
    checkTwoStatus = new Label(composite, SWT.LEFT);
    checkTwoStatus.setText("Off");

    new Label(composite, SWT.RIGHT).setText("Radio Status:");
    radioStatus = new Label(composite, SWT.LEFT);
    radioStatus.setText("None");
}

From source file:org.jfree.experimental.chart.swt.editor.SWTOtherEditor.java

/**
 * Creates a new instance./* ww  w  . j  ava  2  s.c o m*/
 * 
 * @param parent  the parent.
 * @param style  the style.
 * @param chart  the chart.
 */
public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));

    // row 1: antialiasing
    this.antialias = new Button(general, SWT.CHECK);
    this.antialias.setText(localizationResources.getString("Draw_anti-aliased"));
    this.antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    this.antialias.setSelection(chart.getAntiAlias());

    //row 2: background paint for the chart
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTOtherEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTOtherEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
}

From source file:Ch11WizardComposite.java

public void createControl(Composite parent) {
    Composite topLevel = new Composite(parent, SWT.NONE);
    topLevel.setLayout(new FillLayout());

    textLabel = new Label(topLevel, SWT.CENTER);
    textLabel.setText("");

    setControl(topLevel);//ww w .ja  v a2  s.  c o  m
    setPageComplete(true);
}

From source file:org.eclipse.swt.examples.graphics.CustomFontTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite mainComp = new Composite(parent, SWT.NONE);
    mainComp.setLayout(new RowLayout());

    // create combo for font face
    Composite comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontFace")); //$NON-NLS-1$
    fontFaceCb = new Combo(comp, SWT.DROP_DOWN);
    for (String name : fontNames) {
        fontFaceCb.add(name);//from   ww w .  j  av  a 2 s  . c  o  m
    }
    fontFaceCb.select(0);
    fontFaceCb.addListener(SWT.Selection, event -> example.redraw());

    // create combo for font style
    comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontStyle")); //$NON-NLS-1$
    fontStyleCb = new Combo(comp, SWT.DROP_DOWN);
    for (String fontStyle : fontStyles) {
        fontStyleCb.add(fontStyle);
    }
    fontStyleCb.select(0);
    fontStyleCb.addListener(SWT.Selection, event -> example.redraw());

    // create spinner for font size (points)
    comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontSize")); //$NON-NLS-1$
    fontPointSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    fontPointSpinner.setMinimum(1);
    fontPointSpinner.setMaximum(1000);
    fontPointSpinner.setSelection(200);
    fontPointSpinner.addListener(SWT.Selection, event -> example.redraw());

    ColorMenu cm = new ColorMenu();
    cm.setColorItems(true);
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        fontForeground = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the background to the 2nd item in the menu (black)
    fontForeground = (GraphicsBackground) menu.getItem(1).getData();

    // create color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(fontForeground.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);
    });
}