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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Sets the receiver's text.

Usage

From source file:GridLayoutDialog.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    Label labelUser;
    Label labelFile;/*from   www .j a va2 s .  c  o  m*/

    final Text textUser;
    final Text textFile;

    Button buttonBrowseFile;
    Button buttonUpload;

    GridLayout gridLayout = new GridLayout(3, false);
    shell.setLayout(gridLayout);

    labelUser = new Label(shell, SWT.NULL);

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.grabExcessHorizontalSpace = true;
    textUser = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textUser.setLayoutData(gridData);

    new Label(shell, SWT.NULL);

    // 2nd row.
    labelFile = new Label(shell, SWT.NULL);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.grabExcessHorizontalSpace = true;
    textFile = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textFile.setLayoutData(gridData);

    buttonBrowseFile = new Button(shell, SWT.PUSH);

    // last row.
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    gridData.horizontalAlignment = GridData.CENTER;
    buttonUpload = new Button(shell, SWT.PUSH);
    buttonUpload.setLayoutData(gridData);

    labelUser.setText("User name: ");
    labelFile.setText("Photo: ");

    buttonBrowseFile.setText("Browse");
    buttonUpload.setText("Upload");

    buttonBrowseFile.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN);
            String file = dialog.open();
            if (file != null) {
                textFile.setText(file);
            }
        }
    });

    buttonUpload.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println(textUser.getText());
            System.out.println(textFile.getText());
            shell.dispose();
        }
    });

    shell.pack();
    shell.open();
    textUser.forceFocus();

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

From source file:DragTextToLabel.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    Text text = new Text(shell, SWT.BORDER | SWT.SINGLE);

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    DragSource source = new DragSource(text, DND.DROP_MOVE | DND.DROP_COPY);
    source.setTransfer(types);//from ww  w. ja  va 2s  .co  m

    source.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            // Get the selected items in the drag source
            DragSource ds = (DragSource) event.widget;
            Text text = (Text) ds.getControl();

            event.data = text.getSelectionText();
        }
    });

    Label label = new Label(shell, SWT.BORDER);
    // Create the drop target
    DropTarget target = new DropTarget(label, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT) {
                event.detail = (event.operations & DND.DROP_COPY) != 0 ? DND.DROP_COPY : DND.DROP_NONE;
            }

            // Allow dropping text only
            for (int i = 0, n = event.dataTypes.length; i < n; i++) {
                if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
                    event.currentDataType = event.dataTypes[i];
                }
            }
        }

        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
        }

        public void drop(DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Get the dropped data
                DropTarget target = (DropTarget) event.widget;
                Label label = (Label) target.getControl();
                String data = (String) event.data;

                label.setText(data);
                label.redraw();
            }
        }
    });

    text.setBounds(10, 10, 100, 25);
    label.setBounds(10, 55, 100, 25);
    shell.open();

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

From source file:Snippet125.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.BORDER);
    for (int i = 0; i < 20; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("item " + i);
    }/* w  w w .  ja v a  2s .  c  om*/
    // Disable native tooltip
    table.setToolTipText("");

    // Implement a "fake" tooltip
    final Listener labelListener = new Listener() {
        public void handleEvent(Event event) {
            Label label = (Label) event.widget;
            Shell shell = label.getShell();
            switch (event.type) {
            case SWT.MouseDown:
                Event e = new Event();
                e.item = (TableItem) label.getData("_TABLEITEM");
                // Assuming table is single select, set the selection as if
                // the mouse down event went through to the table
                table.setSelection(new TableItem[] { (TableItem) e.item });
                table.notifyListeners(SWT.Selection, e);
                // fall through
            case SWT.MouseExit:
                shell.dispose();
                break;
            }
        }
    };

    Listener tableListener = new Listener() {
        Shell tip = null;

        Label label = null;

        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
            case SWT.KeyDown:
            case SWT.MouseMove: {
                if (tip == null)
                    break;
                tip.dispose();
                tip = null;
                label = null;
                break;
            }
            case SWT.MouseHover: {
                TableItem item = table.getItem(new Point(event.x, event.y));
                if (item != null) {
                    if (tip != null && !tip.isDisposed())
                        tip.dispose();
                    tip = new Shell(shell, SWT.ON_TOP | SWT.TOOL);
                    tip.setLayout(new FillLayout());
                    label = new Label(tip, SWT.NONE);
                    label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                    label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                    label.setData("_TABLEITEM", item);
                    label.setText("tooltip " + item.getText());
                    label.addListener(SWT.MouseExit, labelListener);
                    label.addListener(SWT.MouseDown, labelListener);
                    Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    Rectangle rect = item.getBounds(0);
                    Point pt = table.toDisplay(rect.x, rect.y);
                    tip.setBounds(pt.x, pt.y, size.x, size.y);
                    tip.setVisible(true);
                }
            }
            }
        }
    };
    table.addListener(SWT.Dispose, tableListener);
    table.addListener(SWT.KeyDown, tableListener);
    table.addListener(SWT.MouseMove, tableListener);
    table.addListener(SWT.MouseHover, tableListener);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 125");
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.BORDER);
    for (int i = 0; i < 20; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("item " + i);
    }/*from   ww w.  j a v  a 2s  .  c  om*/
    // Disable native tooltip
    table.setToolTipText("");

    // Implement a "fake" tooltip
    final Listener labelListener = event -> {
        Label label = (Label) event.widget;
        Shell shell1 = label.getShell();
        switch (event.type) {
        case SWT.MouseDown:
            Event e = new Event();
            e.item = (TableItem) label.getData("_TABLEITEM");
            // Assuming table is single select, set the selection as if
            // the mouse down event went through to the table
            table.setSelection(new TableItem[] { (TableItem) e.item });
            table.notifyListeners(SWT.Selection, e);
            shell1.dispose();
            table.setFocus();
            break;
        case SWT.MouseExit:
            shell1.dispose();
            break;
        }
    };

    Listener tableListener = new Listener() {
        Shell tip = null;
        Label label = null;

        @Override
        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
            case SWT.KeyDown:
            case SWT.MouseMove: {
                if (tip == null)
                    break;
                tip.dispose();
                tip = null;
                label = null;
                break;
            }
            case SWT.MouseHover: {
                TableItem item = table.getItem(new Point(event.x, event.y));
                if (item != null) {
                    if (tip != null && !tip.isDisposed())
                        tip.dispose();
                    tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
                    tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                    FillLayout layout = new FillLayout();
                    layout.marginWidth = 2;
                    tip.setLayout(layout);
                    label = new Label(tip, SWT.NONE);
                    label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                    label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                    label.setData("_TABLEITEM", item);
                    label.setText(item.getText());
                    label.addListener(SWT.MouseExit, labelListener);
                    label.addListener(SWT.MouseDown, labelListener);
                    Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    Rectangle rect = item.getBounds(0);
                    Point pt = table.toDisplay(rect.x, rect.y);
                    tip.setBounds(pt.x, pt.y, size.x, size.y);
                    tip.setVisible(true);
                }
            }
            }
        }
    };
    table.addListener(SWT.Dispose, tableListener);
    table.addListener(SWT.KeyDown, tableListener);
    table.addListener(SWT.MouseMove, tableListener);
    table.addListener(SWT.MouseHover, tableListener);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TooltipTableItem.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Table table = new Table(shell, SWT.BORDER);
    for (int i = 0; i < 20; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText("item " + i);
    }/*from  w ww . j  a  v a2 s . co m*/
    // Disable native tooltip
    table.setToolTipText("");

    // Implement a "fake" tooltip
    final Listener labelListener = new Listener() {
        public void handleEvent(Event event) {
            Label label = (Label) event.widget;
            Shell shell = label.getShell();
            switch (event.type) {
            case SWT.MouseDown:
                Event e = new Event();
                e.item = (TableItem) label.getData("_TABLEITEM");
                // Assuming table is single select, set the selection as if
                // the mouse down event went through to the table
                table.setSelection(new TableItem[] { (TableItem) e.item });
                table.notifyListeners(SWT.Selection, e);
                shell.dispose();
                table.setFocus();
                break;
            case SWT.MouseExit:
                shell.dispose();
                break;
            }
        }
    };

    Listener tableListener = new Listener() {
        Shell tip = null;

        Label label = null;

        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
            case SWT.KeyDown:
            case SWT.MouseMove: {
                if (tip == null)
                    break;
                tip.dispose();
                tip = null;
                label = null;
                break;
            }
            case SWT.MouseHover: {
                TableItem item = table.getItem(new Point(event.x, event.y));
                if (item != null) {
                    if (tip != null && !tip.isDisposed())
                        tip.dispose();
                    tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
                    tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                    FillLayout layout = new FillLayout();
                    layout.marginWidth = 2;
                    tip.setLayout(layout);
                    label = new Label(tip, SWT.NONE);
                    label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                    label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                    label.setData("_TABLEITEM", item);
                    label.setText(item.getText());
                    label.addListener(SWT.MouseExit, labelListener);
                    label.addListener(SWT.MouseDown, labelListener);
                    Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                    Rectangle rect = item.getBounds(0);
                    Point pt = table.toDisplay(rect.x, rect.y);
                    tip.setBounds(pt.x, pt.y, size.x, size.y);
                    tip.setVisible(true);
                }
            }
            }
        }
    };
    table.addListener(SWT.Dispose, tableListener);
    table.addListener(SWT.KeyDown, tableListener);
    table.addListener(SWT.MouseMove, tableListener);
    table.addListener(SWT.MouseHover, tableListener);
    shell.pack();
    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;/* ww  w .  j ava  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:ExampleGUI.java

public static void main(String[] args) {
    // create a shell...
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("KTable examples");

    // put a tab folder in it...
    TabFolder tabFolder = new TabFolder(shell, SWT.NONE);

    // Item 1: a Text Table
    TabItem item1 = new TabItem(tabFolder, SWT.NONE);
    item1.setText("Text Table");
    Composite comp1 = new Composite(tabFolder, SWT.NONE);
    item1.setControl(comp1);/*from   w ww  .ja  v  a  2 s.co m*/
    comp1.setLayout(new FillLayout());

    // put a table in tabItem1...
    KTable table = new KTable(comp1, SWT.V_SCROLL | SWT.H_SCROLL);
    // table.setRowSelectionMode(true);
    table.setMultiSelectionMode(true);
    table.setModel(new KTableModelExample());
    table.addCellSelectionListener(new KTableCellSelectionListener() {
        public void cellSelected(int col, int row, int statemask) {
            System.out.println("Cell [" + col + ";" + row + "] selected.");
        }

        public void fixedCellSelected(int col, int row, int statemask) {
            System.out.println("Header [" + col + ";" + row + "] selected.");
        }

    });

    table.addCellResizeListener(new KTableCellResizeListener() {
        public void columnResized(int col, int newWidth) {
            System.out.println("Column " + col + " resized to " + newWidth);
        }

        public void rowResized(int newHeight) {
            System.out.println("Rows resized to " + newHeight);
        }

    });

    // Item 2: a Color Palette
    TabItem item2 = new TabItem(tabFolder, SWT.NONE);
    item2.setText("Color Palette");
    Composite comp2 = new Composite(tabFolder, SWT.NONE);
    item2.setControl(comp2);
    comp2.setLayout(new FillLayout());

    // put a table in tabItem2...
    final KTable table2 = new KTable(comp2, SWT.NONE);
    table2.setModel(new PaletteExampleModel());
    table2.setRowSelectionMode(false);
    table2.setMultiSelectionMode(false);
    final Label label = new Label(comp2, SWT.NONE);
    label.setText("Click a cell...");
    table2.addCellSelectionListener(new KTableCellSelectionAdapter() {
        public void cellSelected(int col, int row, int statemask) {
            RGB rgb = (RGB) table2.getModel().getContentAt(col, row);
            label.setText("R: " + rgb.red + "\nG: " + rgb.green + "\nB: " + rgb.blue);
        }
    });

    // Item 3: Town table
    TabItem item3 = new TabItem(tabFolder, SWT.NONE);
    item3.setText("Towns");
    Composite comp3 = new Composite(tabFolder, SWT.NONE);
    item3.setControl(comp3);
    comp3.setLayout(new FillLayout());

    // put a table in tabItem3...
    final KTable table3 = new KTable(comp3, SWT.FLAT | SWT.H_SCROLL);
    table3.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    table3.setModel(new TownExampleModel());
    table3.setRowSelectionMode(true);
    table3.setMultiSelectionMode(false);

    // display the shell...
    shell.setSize(600, 600);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

static void createChildren(Composite parent) {
    parent.setLayout(new RowLayout());
    List list = new List(parent, SWT.BORDER | SWT.MULTI);
    list.add("List item 1");
    list.add("List item 2");
    Label label = new Label(parent, SWT.NONE);
    label.setText("Label");
    Button button = new Button(parent, SWT.RADIO);
    button.setText("Radio Button");
    button = new Button(parent, SWT.CHECK);
    button.setText("Check box Button");
    button = new Button(parent, SWT.PUSH);
    button.setText("Push Button");
    Text text = new Text(parent, SWT.BORDER);
    text.setText("Text");
}

From source file:Snippet78.java

public static void setDragDrop(final Label label) {

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;

    final DragSource source = new DragSource(label, operations);
    source.setTransfer(types);/*from www  . j av a2 s .  co  m*/
    source.addDragListener(new DragSourceListener() {
        public void dragStart(DragSourceEvent event) {
            event.doit = (label.getText().length() != 0);
        }

        public void dragSetData(DragSourceEvent event) {
            event.data = label.getText();
        }

        public void dragFinished(DragSourceEvent event) {
            if (event.detail == DND.DROP_MOVE)
                label.setText("");
        }
    });

    DropTarget target = new DropTarget(label, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            label.setText((String) event.data);
        }
    });
}

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

public static void setDragDrop(final Label label) {

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;

    final DragSource source = new DragSource(label, operations);
    source.setTransfer(types);// w w  w. j a  v a  2s. c o  m
    source.addDragListener(new DragSourceListener() {
        @Override
        public void dragStart(DragSourceEvent event) {
            event.doit = (label.getText().length() != 0);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            event.data = label.getText();
        }

        @Override
        public void dragFinished(DragSourceEvent event) {
            if (event.detail == DND.DROP_MOVE)
                label.setText("");
        }
    });

    DropTarget target = new DropTarget(label, operations);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        @Override
        public void drop(DropTargetEvent event) {
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }
            label.setText((String) event.data);
        }
    });
}