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:com.bdaum.zoom.report.internal.wizards.ReportComponent.java

public ReportComponent(Composite parent, int style, int preview) {
    super(parent, style);
    this.preview = preview;
    setLayout(new FillLayout());
    stack = new Composite(this, SWT.NONE);
    stackLayout = new StackLayout();
    stack.setLayout(stackLayout);//w w  w.  ja  v a 2 s. c o m

    chartComposite = new ChartComposite(stack, SWT.NONE, null, preview == Integer.MAX_VALUE,
            preview == Integer.MAX_VALUE, preview == Integer.MAX_VALUE, preview == Integer.MAX_VALUE,
            preview == Integer.MAX_VALUE);
    chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    pendingComp = new Composite(stack, SWT.NONE);
    pendingComp.setLayout(new GridLayout(1, false));
    Label label = new Label(pendingComp, SWT.NONE);
    label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    label.setText(Messages.ReportPage_pending);
    if (preview == Integer.MAX_VALUE) {
        progressBar = new ProgressIndicator(pendingComp, SWT.BORDER);
        GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
        data.heightHint = PROGRESS_THICKNESS;
        progressBar.setLayoutData(data);
    }
    stackLayout.topControl = pendingComp;
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

public void open(Display display) {
    Shell shell = new Shell(display);
    shell.setText("Drag and Drop Example");
    shell.setLayout(new FillLayout());

    itemImage = new Image(display, DNDExample.class.getResourceAsStream("openFolder.gif"));

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);//  w  ww .  jav  a  2  s  .  co m
    parent.setLayout(new FormLayout());

    Label dragLabel = new Label(parent, SWT.LEFT);
    dragLabel.setText("Drag Source:");

    Group dragWidgetGroup = new Group(parent, SWT.NONE);
    dragWidgetGroup.setText("Widget");
    createDragWidget(dragWidgetGroup);

    Composite cLeft = new Composite(parent, SWT.NONE);
    cLeft.setLayout(new GridLayout(2, false));

    Group dragOperationsGroup = new Group(cLeft, SWT.NONE);
    dragOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    dragOperationsGroup.setText("Allowed Operation(s):");
    createDragOperations(dragOperationsGroup);

    Group dragTypesGroup = new Group(cLeft, SWT.NONE);
    dragTypesGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    dragTypesGroup.setText("Transfer Type(s):");
    createDragTypes(dragTypesGroup);

    dragConsole = new Text(cLeft, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dragConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Menu menu = new Menu(shell, SWT.POP_UP);
    MenuItem item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(widgetSelectedAdapter(e -> dragConsole.setText("")));
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(widgetSelectedAdapter(e -> {
        MenuItem eItem = (MenuItem) e.widget;
        dragEventDetail = eItem.getSelection();
    }));
    dragConsole.setMenu(menu);

    Label dropLabel = new Label(parent, SWT.LEFT);
    dropLabel.setText("Drop Target:");

    Group dropWidgetGroup = new Group(parent, SWT.NONE);
    dropWidgetGroup.setText("Widget");
    createDropWidget(dropWidgetGroup);

    Composite cRight = new Composite(parent, SWT.NONE);
    cRight.setLayout(new GridLayout(2, false));

    Group dropOperationsGroup = new Group(cRight, SWT.NONE);
    dropOperationsGroup.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 2));
    dropOperationsGroup.setText("Allowed Operation(s):");
    createDropOperations(dropOperationsGroup);

    Group dropTypesGroup = new Group(cRight, SWT.NONE);
    dropTypesGroup.setText("Transfer Type(s):");
    createDropTypes(dropTypesGroup);

    Group feedbackTypesGroup = new Group(cRight, SWT.NONE);
    feedbackTypesGroup.setText("Feedback Type(s):");
    createFeedbackTypes(feedbackTypesGroup);

    dropConsole = new Text(cRight, SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    dropConsole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    menu = new Menu(shell, SWT.POP_UP);
    item = new MenuItem(menu, SWT.PUSH);
    item.setText("Clear");
    item.addSelectionListener(widgetSelectedAdapter(e -> dropConsole.setText("")));
    item = new MenuItem(menu, SWT.CHECK);
    item.setText("Show Event detail");
    item.addSelectionListener(widgetSelectedAdapter(e -> {
        MenuItem eItem = (MenuItem) e.widget;
        dropEventDetail = eItem.getSelection();
    }));
    dropConsole.setMenu(menu);

    if (dragEnabled)
        createDragSource();
    if (dropEnabled)
        createDropTarget();

    int height = 200;
    FormData data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(0, 10);
    dragLabel.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dragLabel, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.height = height;
    dragWidgetGroup.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dragWidgetGroup, 10);
    data.left = new FormAttachment(0, 10);
    data.right = new FormAttachment(50, -10);
    data.bottom = new FormAttachment(100, -10);
    cLeft.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(0, 10);
    data.left = new FormAttachment(cLeft, 10);
    dropLabel.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dropLabel, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.height = height;
    dropWidgetGroup.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(dropWidgetGroup, 10);
    data.left = new FormAttachment(cLeft, 10);
    data.right = new FormAttachment(100, -10);
    data.bottom = new FormAttachment(100, -10);
    cRight.setLayoutData(data);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();

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

From source file:CustomControlExample.java

/**
 * Creates and opens the "Listener selection" dialog.
 */// w  w w  . j a  v  a2  s . c  o  m
void createListenerSelectionDialog() {
    final Shell dialog = new Shell(tabFolderPage.getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setText(ControlExample.getResourceString("Select_Listeners"));
    dialog.setLayout(new GridLayout(2, false));
    final Table table = new Table(dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.verticalSpan = 2;
    table.setLayoutData(data);
    for (int i = 0; i < EVENT_NAMES.length; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(EVENT_NAMES[i]);
        item.setChecked(eventsFilter[i]);
    }
    final String[] customNames = getCustomEventNames();
    for (int i = 0; i < customNames.length; i++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(customNames[i]);
        item.setChecked(eventsFilter[EVENT_NAMES.length + i]);
    }
    Button selectAll = new Button(dialog, SWT.PUSH);
    selectAll.setText(ControlExample.getResourceString("Select_All"));
    selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    selectAll.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getItems();
            for (int i = 0; i < EVENT_NAMES.length; i++) {
                items[i].setChecked(true);
            }
            for (int i = 0; i < customNames.length; i++) {
                items[EVENT_NAMES.length + i].setChecked(true);
            }
        }
    });
    Button deselectAll = new Button(dialog, SWT.PUSH);
    deselectAll.setText(ControlExample.getResourceString("Deselect_All"));
    deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
    deselectAll.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getItems();
            for (int i = 0; i < EVENT_NAMES.length; i++) {
                items[i].setChecked(false);
            }
            for (int i = 0; i < customNames.length; i++) {
                items[EVENT_NAMES.length + i].setChecked(false);
            }
        }
    });
    new Label(dialog, SWT.NONE); /* Filler */
    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText(ControlExample.getResourceString("OK"));
    dialog.setDefaultButton(ok);
    ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getItems();
            for (int i = 0; i < EVENT_NAMES.length; i++) {
                eventsFilter[i] = items[i].getChecked();
            }
            for (int i = 0; i < customNames.length; i++) {
                eventsFilter[EVENT_NAMES.length + i] = items[EVENT_NAMES.length + i].getChecked();
            }
            dialog.dispose();
        }
    });
    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!dialog.getDisplay().readAndDispatch())
            dialog.getDisplay().sleep();
    }
}

From source file:PrintKTableExample.java

/**
 * @param parent//from w w w .  j a  va 2 s. c  o m
 * @param title
 * @param icon
 */
public PrintPreview(Shell parent, String title, Image icon, PDocument doc) {
    super(parent, title, icon);
    createContents();
    document = doc;
    page = 1;
    percent = 100;
    layoutNeccessary = true;

    addToolItem("print", "Drucken ...", IconSource.getImage("print"));
    addToolItem("first", "erste Seite", IconSource.getImage("i2"));
    addToolItem("prev", "vorherige Seite", IconSource.getImage("i3"));
    addToolItem("next", "nachste Seite", IconSource.getImage("i4"));
    addToolItem("last", "letzte Seite", IconSource.getImage("i5"));
    Button close = addButtonRight("&SchlieBen", "");
    // addButtonRight("Seite &einrichten","");
    close.setFocus();

    guiShell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent arg0) {
            onClose();
        }
    });

    Composite comp = new Composite(guiToolBarArea, SWT.BORDER);
    comp.setLayout(new FillLayout());
    guiPageLabel = new CLabel(comp, SWT.NONE);
    guiPageLabel.setText(guiPageLabel.getText() + "        ");
    guiPageLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    adjustToToolBar(comp);

    guiZoom = new Combo(guiToolBarArea, SWT.BORDER | SWT.READ_ONLY);
    guiZoom.add("500%");
    guiZoom.add("200%");
    guiZoom.add("100%");
    guiZoom.add("80%");
    guiZoom.add("50%");
    guiZoom.add("20%");
    guiZoom.add("passend");
    adjustToToolBar(guiZoom);
    guiZoom.setToolTipText("VorschaugroBe");
    guiZoom.select(2);
    guiZoom.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent arg0) {
            onCombo(((Combo) arg0.widget).getText());
        }
    });
    guiMainArea.setLayout(new FillLayout());
    guiScrollArea = new ScrolledComposite(guiMainArea, SWT.H_SCROLL | SWT.V_SCROLL);
    guiImageLabel = new Label(guiScrollArea, SWT.NONE);
    guiScrollArea.setContent(guiImageLabel);
    if (guiImageLabel.getImage() != null)
        guiImageLabel.getImage().dispose();
    guiImageLabel.setImage(getPageImage(page));
    guiPageLabel.setText(" Seite " + page + " von " + document.getNumOfPages() + "       ");
    guiImageLabel.setSize(guiImageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT));

}

From source file:CustomControlExample.java

void createSetGetDialog(int x, int y, String[] methodNames) {
    final Shell dialog = new Shell(eventConsole.getShell(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MODELESS);
    dialog.setLayout(new GridLayout(2, false));
    dialog.setText(getTabText() + " " + ControlExample.getResourceString("Set_Get"));
    nameCombo = new Combo(dialog, SWT.NONE);
    nameCombo.setItems(methodNames);/*  w w  w.j  a  v  a 2  s  .  com*/
    nameCombo.setText(methodNames[0]);
    nameCombo.setVisibleItemCount(methodNames.length);
    nameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    nameCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            resetLabels();
        }
    });
    returnTypeLabel = new Label(dialog, SWT.NONE);
    returnTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    setButton = new Button(dialog, SWT.PUSH);
    setButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    setButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setValue();
        }
    });
    setText = new Text(dialog, SWT.SINGLE | SWT.BORDER);
    setText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    getButton = new Button(dialog, SWT.PUSH);
    getButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
    getButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            getValue();
        }
    });
    getText = new Text(dialog, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.widthHint = 240;
    data.heightHint = 200;
    getText.setLayoutData(data);
    resetLabels();
    dialog.setDefaultButton(setButton);
    dialog.pack();
    dialog.setLocation(x, y);
    dialog.open();
}

From source file:LayoutExample.java

/**
 * Creates the control widgets./*from w w  w.  j  a v  a 2  s  .  com*/
 */
void createControlWidgets() {
    /* Rearrange the layout of the control group */
    size.setLayoutData(new GridData());

    /* Controls the margins and spacing of the GridLayout */
    String[] marginValues = new String[] { "0", "3", "5", "10" };
    Group marginGroup = new Group(controlGroup, SWT.NONE);
    marginGroup.setText(LayoutExample.getResourceString("Margins_Spacing"));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.verticalSpan = 2;
    marginGroup.setLayoutData(data);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    marginGroup.setLayout(layout);
    new Label(marginGroup, SWT.NONE).setText("marginHeight");
    marginHeight = new Combo(marginGroup, SWT.NONE);
    marginHeight.setItems(marginValues);
    marginHeight.select(2);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 60;
    marginHeight.setLayoutData(data);
    marginHeight.addSelectionListener(selectionListener);
    marginHeight.addTraverseListener(traverseListener);
    new Label(marginGroup, SWT.NONE).setText("marginWidth");
    marginWidth = new Combo(marginGroup, SWT.NONE);
    marginWidth.setItems(marginValues);
    marginWidth.select(2);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 60;
    marginWidth.setLayoutData(data);
    marginWidth.addSelectionListener(selectionListener);
    marginWidth.addTraverseListener(traverseListener);
    new Label(marginGroup, SWT.NONE).setText("horizontalSpacing");
    horizontalSpacing = new Combo(marginGroup, SWT.NONE);
    horizontalSpacing.setItems(marginValues);
    horizontalSpacing.select(2);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 60;
    horizontalSpacing.setLayoutData(data);
    horizontalSpacing.addSelectionListener(selectionListener);
    horizontalSpacing.addTraverseListener(traverseListener);
    new Label(marginGroup, SWT.NONE).setText("verticalSpacing");
    verticalSpacing = new Combo(marginGroup, SWT.NONE);
    verticalSpacing.setItems(marginValues);
    verticalSpacing.select(2);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 60;
    verticalSpacing.setLayoutData(data);
    verticalSpacing.addSelectionListener(selectionListener);
    verticalSpacing.addTraverseListener(traverseListener);

    /* Controls the columns in the GridLayout */
    Group columnGroup = new Group(controlGroup, SWT.NONE);
    columnGroup.setText(LayoutExample.getResourceString("Columns"));
    layout = new GridLayout();
    layout.numColumns = 2;
    columnGroup.setLayout(layout);
    data = new GridData(GridData.VERTICAL_ALIGN_FILL);
    columnGroup.setLayoutData(data);
    numColumns = new Text(columnGroup, SWT.BORDER);
    numColumns.setText("1");
    numColumns.addSelectionListener(selectionListener);
    numColumns.addTraverseListener(traverseListener);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = 15;
    numColumns.setLayoutData(data);
    new Label(columnGroup, SWT.NONE).setText("numColumns");
    makeColumnsEqualWidth = new Button(columnGroup, SWT.CHECK);
    makeColumnsEqualWidth.setText("makeColumnsEqualWidth");
    makeColumnsEqualWidth.addSelectionListener(selectionListener);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.horizontalIndent = 14;
    makeColumnsEqualWidth.setLayoutData(data);

    /* Add common controls */
    super.createControlWidgets();
    controlGroup.pack();
}

From source file:org.eclipse.swt.examples.texteditor.TextEditor.java

void setLink() {
    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM);
    dialog.setLayout(new GridLayout(2, false));
    dialog.setText(getResourceString("SetLink")); //$NON-NLS-1$
    Label label = new Label(dialog, SWT.NONE);
    label.setText(getResourceString("URL")); //$NON-NLS-1$
    final Text text = new Text(dialog, SWT.SINGLE);
    text.setLayoutData(new GridData(200, SWT.DEFAULT));
    if (link != null) {
        text.setText(link);//from ww w.j a  va  2 s  .  c o m
        text.selectAll();
    }
    final Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText(getResourceString("Ok")); //$NON-NLS-1$
    final Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText(getResourceString("Cancel")); //$NON-NLS-1$
    Listener listener = event -> {
        if (event.widget == okButton) {
            link = text.getText();
            setStyle(UNDERLINE_LINK);
        }
        dialog.dispose();
    };
    okButton.addListener(SWT.Selection, listener);
    cancelButton.addListener(SWT.Selection, listener);
    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void headerShowToolTip(int x) {
    String tooltip = headerGetToolTip(x);
    if (tooltip == null || tooltip.length() == 0)
        return;//from www  .j av  a 2s  .  co  m

    if (toolTipShell == null) {
        toolTipShell = new Shell(getShell(), SWT.ON_TOP | SWT.TOOL);
        toolTipLabel = new Label(toolTipShell, SWT.CENTER);
        Display display = toolTipShell.getDisplay();
        toolTipLabel.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
        toolTipLabel.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
        for (int toolTipEvent : toolTipEvents) {
            header.addListener(toolTipEvent, toolTipListener);
        }
    }
    if (headerUpdateToolTip(x)) {
        toolTipShell.setVisible(true);
    } else {
        headerHideToolTip();
    }
}

From source file:ImageAnalyzer.java

int showBMPDialog() {
    final int[] bmpType = new int[1];
    bmpType[0] = SWT.IMAGE_BMP;//from   w w w. j  a  v  a  2s .  c om
    SelectionListener radioSelected = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Button radio = (Button) event.widget;
            if (radio.getSelection())
                bmpType[0] = ((Integer) radio.getData()).intValue();
        }
    };
    // need to externalize strings
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);

    dialog.setText("Save_as");
    dialog.setLayout(new GridLayout());

    Label label = new Label(dialog, SWT.NONE);
    label.setText("Save_as");

    Button radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_no_compress");
    radio.setSelection(true);
    radio.setData(new Integer(SWT.IMAGE_BMP));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_rle_compress");
    radio.setData(new Integer(SWT.IMAGE_BMP_RLE));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_os2");
    radio.setData(new Integer(SWT.IMAGE_OS2_BMP));
    radio.addSelectionListener(radioSelected);

    label = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText("OK");
    GridData data = new GridData();
    data.horizontalAlignment = SWT.CENTER;
    data.widthHint = 75;
    ok.setLayoutData(data);
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dialog.close();
        }
    });

    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    return bmpType[0];
}

From source file:CustomControlExample.java

/**
 * Creates the "Colors" group.//  w w  w  .  j av a 2s. c  o  m
 */
void createColorGroup() {
    super.createColorGroup();

    itemGroup = new Group(colorGroup, SWT.NONE);
    itemGroup.setText(ControlExample.getResourceString("Tree_Item_Colors"));
    GridData data = new GridData();
    data.horizontalSpan = 2;
    itemGroup.setLayoutData(data);
    itemGroup.setLayout(new GridLayout(2, false));
    new Label(itemGroup, SWT.NONE).setText(ControlExample.getResourceString("Foreground_Color"));
    itemForegroundButton = new Button(itemGroup, SWT.PUSH);
    new Label(itemGroup, SWT.NONE).setText(ControlExample.getResourceString("Background_Color"));
    itemBackgroundButton = new Button(itemGroup, SWT.PUSH);
    itemFontButton = new Button(itemGroup, SWT.PUSH);
    itemFontButton.setText(ControlExample.getResourceString("Font"));
    itemFontButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    Shell shell = colorGroup.getShell();
    final ColorDialog foregroundDialog = new ColorDialog(shell);
    final ColorDialog backgroundDialog = new ColorDialog(shell);
    final FontDialog fontDialog = new FontDialog(shell);

    int imageSize = 12;
    Display display = shell.getDisplay();
    itemForegroundImage = new Image(display, imageSize, imageSize);
    itemBackgroundImage = new Image(display, imageSize, imageSize);

    /* Add listeners to set the colors and font */
    itemForegroundButton.setImage(itemForegroundImage);
    itemForegroundButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color oldColor = itemForegroundColor;
            if (oldColor == null)
                oldColor = textNode1.getForeground();
            foregroundDialog.setRGB(oldColor.getRGB());
            RGB rgb = foregroundDialog.open();
            if (rgb == null)
                return;
            oldColor = itemForegroundColor;
            itemForegroundColor = new Color(event.display, rgb);
            setItemForeground();
            if (oldColor != null)
                oldColor.dispose();
        }
    });
    itemBackgroundButton.setImage(itemBackgroundImage);
    itemBackgroundButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Color oldColor = itemBackgroundColor;
            if (oldColor == null)
                oldColor = textNode1.getBackground();
            backgroundDialog.setRGB(oldColor.getRGB());
            RGB rgb = backgroundDialog.open();
            if (rgb == null)
                return;
            oldColor = itemBackgroundColor;
            itemBackgroundColor = new Color(event.display, rgb);
            setItemBackground();
            if (oldColor != null)
                oldColor.dispose();
        }
    });
    itemFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Font oldFont = itemFont;
            if (oldFont == null)
                oldFont = textNode1.getFont();
            fontDialog.setFontList(oldFont.getFontData());
            FontData fontData = fontDialog.open();
            if (fontData == null)
                return;
            oldFont = itemFont;
            itemFont = new Font(event.display, fontData);
            setItemFont();
            setExampleWidgetSize();
            if (oldFont != null)
                oldFont.dispose();
        }
    });
    shell.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            if (itemBackgroundImage != null)
                itemBackgroundImage.dispose();
            if (itemForegroundImage != null)
                itemForegroundImage.dispose();
            if (itemBackgroundColor != null)
                itemBackgroundColor.dispose();
            if (itemForegroundColor != null)
                itemForegroundColor.dispose();
            if (itemFont != null)
                itemFont.dispose();
            itemBackgroundColor = null;
            itemForegroundColor = null;
            itemFont = null;
        }
    });
}