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:MainClass.java

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    new Label(composite, SWT.LEFT).setText("Please enter your complaints");
    Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    setControl(composite);/*from w  w w.  jav a2s.  c  o  m*/
}

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);//  ww  w.  j a v a  2 s.  c o  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:ShowMessageBox.java

/**
 * Creates the main window's contents/*from  www  . ja  v a  2  s.  co  m*/
 * 
 * @param shell the parent shell
 */
private void createContents(final Shell shell) {
    shell.setLayout(new GridLayout(2, false));

    // Create the dropdown to allow icon selection
    new Label(shell, SWT.NONE).setText("Icon:");
    final Combo icons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0, n = ICONS.length; i < n; i++)
        icons.add(ICONS[i]);
    icons.select(0);

    // Create the dropdown to allow button selection
    new Label(shell, SWT.NONE).setText("Buttons:");
    final Combo buttons = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0, n = BUTTONS.length; i < n; i++)
        buttons.add(BUTTONS[i]);
    buttons.select(0);

    // Create the entry field for the message
    new Label(shell, SWT.NONE).setText("Message:");
    final Text message = new Text(shell, SWT.BORDER);
    message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label to show the return from the open call
    new Label(shell, SWT.NONE).setText("Return:");
    final Label returnVal = new Label(shell, SWT.NONE);
    returnVal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the button and event handler
    // to display the message box
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Show Message");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Clear any previously returned value
            returnVal.setText("");

            // This will hold the style to pass to the MessageBox constructor
            int style = 0;

            // Determine which icon was selected and
            // add it to the style
            switch (icons.getSelectionIndex()) {
            case 0:
                style |= SWT.ICON_ERROR;
                break;
            case 1:
                style |= SWT.ICON_INFORMATION;
                break;
            case 2:
                style |= SWT.ICON_QUESTION;
                break;
            case 3:
                style |= SWT.ICON_WARNING;
                break;
            case 4:
                style |= SWT.ICON_WORKING;
                break;
            }

            // Determine which set of buttons was selected
            // and add it to the style
            switch (buttons.getSelectionIndex()) {
            case 0:
                style |= SWT.OK;
                break;
            case 1:
                style |= SWT.OK | SWT.CANCEL;
                break;
            case 2:
                style |= SWT.YES | SWT.NO;
                break;
            case 3:
                style |= SWT.YES | SWT.NO | SWT.CANCEL;
                break;
            case 4:
                style |= SWT.RETRY | SWT.CANCEL;
                break;
            case 5:
                style |= SWT.ABORT | SWT.RETRY | SWT.IGNORE;
                break;
            }

            // Display the message box
            MessageBox mb = new MessageBox(shell, style);
            mb.setText("Message from SWT");
            mb.setMessage(message.getText());
            int val = mb.open();
            String valString = "";
            switch (val) // val contains the constant of the selected button
            {
            case SWT.OK:
                valString = "SWT.OK";
                break;
            case SWT.CANCEL:
                valString = "SWT.CANCEL";
                break;
            case SWT.YES:
                valString = "SWT.YES";
                break;
            case SWT.NO:
                valString = "SWT.NO";
                break;
            case SWT.RETRY:
                valString = "SWT.RETRY";
                break;
            case SWT.ABORT:
                valString = "SWT.ABORT";
                break;
            case SWT.IGNORE:
                valString = "SWT.IGNORE";
                break;
            }
            returnVal.setText(valString);
        }
    });
}

From source file:ShowFileDialog.java

/**
 * Creates the contents for the window/* w w w  .  j a  v  a 2 s .  c o m*/
 * 
 * @param shell the parent shell
 */
public void createContents(final Shell shell) {
    shell.setLayout(new GridLayout(5, true));

    new Label(shell, SWT.NONE).setText("File Name:");

    final Text fileName = new Text(shell, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 4;
    fileName.setLayoutData(data);

    Button multi = new Button(shell, SWT.PUSH);
    multi.setText("Open Multiple...");
    multi.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // User has selected to open multiple files
            FileDialog dlg = new FileDialog(shell, SWT.MULTI);
            dlg.setFilterNames(FILTER_NAMES);
            dlg.setFilterExtensions(FILTER_EXTS);
            String fn = dlg.open();
            if (fn != null) {
                // Append all the selected files. Since getFileNames() returns only 
                // the names, and not the path, prepend the path, normalizing
                // if necessary
                StringBuffer buf = new StringBuffer();
                String[] files = dlg.getFileNames();
                for (int i = 0, n = files.length; i < n; i++) {
                    buf.append(dlg.getFilterPath());
                    if (buf.charAt(buf.length() - 1) != File.separatorChar) {
                        buf.append(File.separatorChar);
                    }
                    buf.append(files[i]);
                    buf.append(" ");
                }
                fileName.setText(buf.toString());
            }
        }
    });

    Button open = new Button(shell, SWT.PUSH);
    open.setText("Open...");
    open.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // User has selected to open a single file
            FileDialog dlg = new FileDialog(shell, SWT.OPEN);
            dlg.setFilterNames(FILTER_NAMES);
            dlg.setFilterExtensions(FILTER_EXTS);
            String fn = dlg.open();
            if (fn != null) {
                fileName.setText(fn);
            }
        }
    });

    Button save = new Button(shell, SWT.PUSH);
    save.setText("Save...");
    save.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // User has selected to save a file
            FileDialog dlg = new FileDialog(shell, SWT.SAVE);
            dlg.setFilterNames(FILTER_NAMES);
            dlg.setFilterExtensions(FILTER_EXTS);
            String fn = dlg.open();
            if (fn != null) {
                fileName.setText(fn);
            }
        }
    });
}

From source file:AdvancedBrowser.java

public AdvancedBrowser(String location) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Advanced Browser");

    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);/*from www  .  ja  v  a  2 s . 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));

    // Go to the initial URL
    if (location != null) {
        browser.setUrl(location);
    }

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet365.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet365 - Transparent Background");
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.spacing = 20;//  w w w .  j a va 2 s  . c o m
    layout.marginWidth = 10;
    layout.marginHeight = 10;
    shell.setLayout(layout);
    // Standard color background for Shell
    // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // Gradient background for Shell
    shell.addListener(SWT.Resize, event -> {
        Rectangle rect = shell.getClientArea();
        Image newImage = new Image(display, Math.max(1, rect.width), 1);
        GC gc = new GC(newImage);
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
        gc.dispose();
        shell.setBackgroundImage(newImage);
        if (oldImage != null)
            oldImage.dispose();
        oldImage = newImage;
    });

    // Transparent
    buttonCheckBox = new Button(shell, SWT.CHECK | SWT.None);
    buttonCheckBox.setText("SET TRANSPARENT");
    buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
    buttonCheckBox.setSelection(false);
    buttonCheckBox.addSelectionListener(widgetSelectedAdapter(e -> {
        boolean transparent = ((Button) e.getSource()).getSelection();
        if (transparent) {
            // ContainerGroup
            containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            for (TabItem item : tabFolder.getItems()) {
                item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            }

            // Native
            nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));

            // Custom
            customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            for (Control control : sashForm.getChildren()) {
                control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT));
            }
            // Default
            push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
            tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));

            // ItemGroup
            itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
        } else {
            // Native
            nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            toolBar.setBackground(null);
            coolBar.setBackground(null);
            label.setBackground(null);
            link.setBackground(null);
            scale.setBackground(null);
            RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB();
            radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255)));
            check.setBackgroundImage(getBackgroundImage(display));
            group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
            slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

            // ContainerGroup
            containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            for (TabItem item : tabFolder.getItems()) {
                item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            }
            // Custom
            customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            cLabel.setBackground((Color) null);
            styledText.setBackground((Color) null);
            sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            for (Control control : sashForm.getChildren()) {
                control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            }
            cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

            gradientCTab.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_RED),
                    display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true);

            // Default
            defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            dateTime.setBackground(null);
            progressBar.setBackground(null);
            expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
            tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

            // ItemGroup
            itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
        }

    }));

    // ContainerGroup
    containerGroup = new Composite(shell, SWT.NONE);
    containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    containerGroup.setToolTipText("CONTAINER");
    layout = new RowLayout();
    layout.spacing = 20;
    containerGroup.setLayout(layout);

    // Native
    nativeGroup = new Composite(shell, SWT.NONE);
    nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    nativeGroup.setToolTipText("NATIVE");
    layout = new RowLayout();
    layout.spacing = 20;
    nativeGroup.setLayout(layout);

    // Custom
    customGroup = new Composite(shell, SWT.NONE);
    customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    customGroup.setToolTipText("CUSTOM");
    layout = new RowLayout();
    layout.spacing = 20;
    customGroup.setLayout(layout);

    // AsDesigned
    defaultBackgroundGroup = new Composite(shell, SWT.NONE);
    defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    defaultBackgroundGroup.setToolTipText("Default Background");
    layout = new RowLayout();
    layout.spacing = 20;
    defaultBackgroundGroup.setLayout(layout);

    // ItemGroup
    itemGroup = new Composite(shell, SWT.NONE);
    itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    itemGroup.setToolTipText("ITEM");
    layout = new RowLayout();
    layout.spacing = 20;
    itemGroup.setLayout(layout);

    // Label
    label = new Label(nativeGroup, SWT.NONE);
    label.setText("Label");

    // Radio button
    radio = new Button(nativeGroup, SWT.RADIO);
    radio.setText("Radio Button");
    radio.setSelection(true);
    radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // Checkbox button with image
    check = new Button(nativeGroup, SWT.CHECK);
    check.setText("CheckBox Image");
    check.setSelection(true);
    check.setBackgroundImage(getBackgroundImage(display));

    // Push Button
    push = new Button(defaultBackgroundGroup, SWT.PUSH);
    push.setText("Push Button");

    // Toolbar
    toolBar = new ToolBar(nativeGroup, SWT.FLAT);
    toolBar.pack();
    ToolItem item = new ToolItem(toolBar, SWT.PUSH);
    item.setText("ToolBar_Item");

    // Coolbar
    coolBar = new CoolBar(nativeGroup, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CoolItem item2 = new CoolItem(coolBar, SWT.NONE);
        Button button = new Button(coolBar, SWT.PUSH);
        button.setText("Button " + i);
        Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        item2.setPreferredSize(item2.computeSize(size.x, size.y));
        item2.setControl(button);
    }
    // Scale
    scale = new Scale(nativeGroup, SWT.None);
    scale.setMaximum(100);
    scale.setSelection(20);

    // Link
    link = new Link(nativeGroup, SWT.NONE);
    link.setText("<a>Sample link</a>");

    // List
    list = new List(nativeGroup, SWT.BORDER);
    list.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    list.add("List_one");
    list.add("List_two");
    list.add("List_three");
    list.add("List_four");

    // Canvas
    canvas = new Canvas(containerGroup, SWT.NONE);
    canvas.setToolTipText("Canvas");
    canvas.addPaintListener(e -> {
        GC gc = e.gc;
        gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
        gc.drawRectangle(e.x + 1, e.y + 1, e.width - 2, e.height - 2);
        gc.drawArc(2, 2, e.width - 4, e.height - 4, 0, 360);
    });

    // Composite
    composite = new Composite(containerGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    composite.setToolTipText("Composite");

    // TabFolder
    tabFolder = new TabFolder(containerGroup, SWT.BORDER);
    tabFolder.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    for (int i = 0; i < 2; i++) {
        TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
        tabItem.setText("TabItem " + i);
        Label label = new Label(tabFolder, SWT.PUSH);
        label.setText("Page " + i);
        tabItem.setControl(label);
        tabItem.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    }
    tabFolder.pack();

    // Group
    group = new Group(containerGroup, SWT.NONE);
    group.setText("Group");

    // Sash
    sash = new Sash(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
    sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
    sash.setLayoutData(new RowData(100, 100));
    sash.setToolTipText("Sash");

    // SashForm
    sashForm = new SashForm(containerGroup, SWT.HORIZONTAL | SWT.BORDER);
    Label leftLabel = new Label(sashForm, SWT.NONE);
    leftLabel.setText("SashForm\nLeft\n...\n...\n...\n...\n...");
    Label rightLabel = new Label(sashForm, SWT.NONE);
    rightLabel.setText("SashForm\nRight\n...\n...\n...\n...\n...");

    // DateTime
    dateTime = new DateTime(defaultBackgroundGroup, SWT.NONE);
    dateTime.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // Text
    text = new Text(nativeGroup, SWT.BORDER);
    text.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    text.setText("text");

    // ProgressBar
    progressBar = new ProgressBar(defaultBackgroundGroup, SWT.NONE);
    progressBar.setMaximum(100);
    progressBar.setSelection(80);

    // Combo
    combo = new Combo(defaultBackgroundGroup, SWT.BORDER);
    combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    combo.add("combo");
    combo.setText("combo");

    // Slider
    slider = new Slider(nativeGroup, SWT.HORIZONTAL | SWT.BORDER);
    slider.setSelection(20);
    slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // CCombo
    ccombo = new CCombo(defaultBackgroundGroup, SWT.BORDER);
    ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    ccombo.add("ccombo");
    ccombo.setText("ccombo");

    // CLable
    cLabel = new CLabel(customGroup, SWT.NONE);
    cLabel.setText("CLabel");

    // Text
    styledText = new StyledText(customGroup, SWT.BORDER);
    styledText.setFont(new Font(display, "Tahoma", 18, SWT.BOLD | SWT.ITALIC));
    styledText.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
    styledText.setText("Styled Text");
    styledText.append("\n");
    styledText.append("Example_string");
    styledText.append("\n");
    styledText.append("One_Two");
    styledText.append("\n");
    styledText.append("Two_Three");

    // CTabFolder
    cTab = new CTabFolder(containerGroup, SWT.BORDER);
    for (int i = 0; i < 2; i++) {
        CTabItem cTabItem = new CTabItem(cTab, SWT.CLOSE, i);
        cTabItem.setText("CTabItem " + (i + 1));
    }
    cTab.setSelection(0);

    // Gradient CTabFolder
    gradientCTab = new CTabFolder(customGroup, SWT.BORDER);
    gradientCTab.setBackground(
            new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED) },
            new int[] { 90 }, true);
    for (int i = 0; i < 2; i++) {
        CTabItem cTabItem = new CTabItem(gradientCTab, SWT.CLOSE, i);
        cTabItem.setText("CTabItem " + (i + 1));
    }
    gradientCTab.setSelection(0);

    // Table
    table = new Table(itemGroup, SWT.V_SCROLL);
    table.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableItem tableItem = new TableItem(table, SWT.NONE);
    tableItem.setText("TableItem - One");
    tableItem = new TableItem(table, SWT.NONE);
    tableItem.setText("TableItem - Two");

    // Tree
    tree = new Tree(itemGroup, SWT.NONE);
    TreeItem treeItem = new TreeItem(tree, SWT.NONE);
    treeItem.setText("Parent");
    TreeItem childItem = new TreeItem(treeItem, SWT.NONE);
    childItem.setText("Child1");
    childItem = new TreeItem(treeItem, SWT.NONE);
    childItem.setText("Child2");
    treeItem.setExpanded(true);
    tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN));

    // ExpandBar
    expandBar = new ExpandBar(itemGroup, SWT.V_SCROLL);
    expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
    for (int i = 1; i <= 2; i++) {
        ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE, 0);
        item1.setText("Expand_Bar_Entry " + i);
        item1.setExpanded(true);
        item1.setHeight(20);
    }

    shell.open();
    shell.pack();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ShowImageFlags.java

/**
 * Creates the main window's contents/*  w  ww .ja  v a 2  s  . co m*/
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new FillLayout());

    // Create labels to hold each image
    new Label(shell, SWT.NONE).setImage(image);
    new Label(shell, SWT.NONE).setImage(copy);
    new Label(shell, SWT.NONE).setImage(disable);
    new Label(shell, SWT.NONE).setImage(gray);
}

From source file:ProgressBarExamples.java

public ProgressBarExamples() {
    init();//from www.java2s  . c o m

    ProgressBar pb1 = new ProgressBar(shell, SWT.NULL);
    final ProgressBar pb2 = new ProgressBar(shell, SWT.SMOOTH);
    ProgressBar pb3 = new ProgressBar(shell, SWT.INDETERMINATE);

    //      pb2.addPaintListener(new PaintListener() {
    //         public void paintControl(PaintEvent e) {
    //            Point point = pb2.getSize();
    //            
    //            Font font = new Font(shell.getDisplay(),"Courier",10,SWT.BOLD);
    //            e.gc.setFont(font);
    //            e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    //            
    //            FontMetrics fontMetrics = e.gc.getFontMetrics();
    //            int stringWidth = fontMetrics.getAverageCharWidth() * 4;
    //            int stringHeight = fontMetrics.getHeight();
    //            
    //            e.gc.drawString("60%", (point.x-stringWidth)/2 , (point.y-stringHeight)/2, true);
    //            font.dispose();
    //         }
    //      });

    pb1.setSelection(60);
    pb2.setSelection(60);

    pb1.setBounds(100, 10, 200, 20);
    pb2.setBounds(100, 40, 200, 20);
    //pb3.setBounds(100, 70, 200, 20);

    Label label = new Label(shell, SWT.NULL);
    label.setText("(default)");
    Label label2 = new Label(shell, SWT.NULL);
    label2.setText("SWT.SMOOTH");

    label.setAlignment(SWT.RIGHT);
    label2.setAlignment(SWT.RIGHT);

    label.setBounds(10, 10, 80, 20);
    label2.setBounds(10, 40, 80, 20);

    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:CoolBarExamples.java

public CoolBarExamples() {
    shell.setLayout(new GridLayout());

    final CoolBar coolBar = new CoolBar(shell, SWT.NONE);

    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // cool item with a text field.
    CoolItem textItem = new CoolItem(coolBar, SWT.NONE);

    Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN);
    text.setText("TEXT");
    text.pack();//  w  w w . j a v a 2  s.c o m

    Point size = text.getSize();
    textItem.setControl(text);
    textItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a label.
    CoolItem labelItem = new CoolItem(coolBar, SWT.NONE);

    Label label = new Label(coolBar, SWT.NONE);
    label.setText("LABEL");
    label.pack();

    size = label.getSize();
    labelItem.setControl(label);
    labelItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a button.
    CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN);

    Composite composite = new Composite(coolBar, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    button1.pack();

    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");
    button2.pack();

    composite.pack();

    size = composite.getSize();
    buttonItem.setControl(composite);
    buttonItem.setSize(buttonItem.computeSize(size.x, size.y));

    //      // Test cool item adding method.
    //      Label label2 = new Label(coolBar, SWT.NONE);
    //      label2.setText("label2");
    //      addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar);

    try {
        setState(coolBar, new File("coolbar.state"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    shell.addListener(SWT.Close, new Listener() {
        public void handleEvent(Event event) {
            try {
                saveState(coolBar, new File("coolbar.state"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    shell.setSize(300, 120);
    // 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:MainClass.java

protected Control createDialogArea(Composite parent) {
    createMessageArea(parent);// ww  w.  j  av  a2s.  c om
    Composite composite = new Composite(parent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    composite.setLayout(new FillLayout());

    label = new Label(composite, SWT.LEFT);
    return composite;
}