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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Sets the receiver's text.

Usage

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 75");
    shell.setLayout(new RowLayout());

    Composite c1 = new Composite(shell, SWT.BORDER);
    c1.setLayout(new RowLayout());
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("B&1");
    Button r1 = new Button(c1, SWT.RADIO);
    r1.setText("R1");
    Button r2 = new Button(c1, SWT.RADIO);
    r2.setText("R&2");
    Button r3 = new Button(c1, SWT.RADIO);
    r3.setText("R3");
    Button b2 = new Button(c1, SWT.PUSH);
    b2.setText("B2");
    List l1 = new List(c1, SWT.SINGLE | SWT.BORDER);
    l1.setItems("L1");
    Button b3 = new Button(c1, SWT.PUSH);
    b3.setText("B&3");
    Button b4 = new Button(c1, SWT.PUSH);
    b4.setText("B&4");

    Composite c2 = new Composite(shell, SWT.BORDER);
    c2.setLayout(new RowLayout());
    Button b5 = new Button(c2, SWT.PUSH);
    b5.setText("B&5");
    Button b6 = new Button(c2, SWT.PUSH);
    b6.setText("B&6");

    List l2 = new List(shell, SWT.SINGLE | SWT.BORDER);
    l2.setItems("L2");

    ToolBar tb1 = new ToolBar(shell, SWT.FLAT | SWT.BORDER);
    ToolItem i1 = new ToolItem(tb1, SWT.RADIO);
    i1.setText("I1");
    ToolItem i2 = new ToolItem(tb1, SWT.RADIO);
    i2.setText("I2");
    Combo combo1 = new Combo(tb1, SWT.READ_ONLY | SWT.BORDER);
    combo1.setItems("C1");
    combo1.setText("C1");
    combo1.pack();/*from   w  w w  .j  av a2  s  . c  o  m*/
    ToolItem i3 = new ToolItem(tb1, SWT.SEPARATOR);
    i3.setWidth(combo1.getSize().x);
    i3.setControl(combo1);
    ToolItem i4 = new ToolItem(tb1, SWT.PUSH);
    i4.setText("I&4");
    ToolItem i5 = new ToolItem(tb1, SWT.CHECK);
    i5.setText("I5");

    Button b7 = new Button(shell, SWT.PUSH);
    b7.setText("B&7");

    Composite c4 = new Composite(shell, SWT.BORDER);
    Composite c5 = new Composite(c4, SWT.BORDER);
    c5.setLayout(new FillLayout());
    new Label(c5, SWT.NONE).setText("No");
    c5.pack();

    Control[] tabList1 = new Control[] { b2, b1, b3 };
    c1.setTabList(tabList1);
    Control[] tabList2 = new Control[] { c1, b7, tb1, c4, c2, l2 };
    shell.setTabList(tabList2);

    shell.pack();
    shell.open();

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

From source file:SWTButtonAction.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setSize(200, 200);//  www .  j a v  a 2s .c  o  m
    shell.setText("Dialogs");
    shell.open();

    final Button opener = new Button(shell, SWT.PUSH);
    opener.setText("Click Me");
    opener.setBounds(20, 20, 50, 25);

    final Text text = new Text(shell, SWT.SHADOW_IN);
    text.setBounds(80, 20, 100, 25);

    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
    dialog.setText("Dialog");
    dialog.setSize(150, 100);

    final Label label = new Label(dialog, SWT.NONE);
    label.setText("OK to proceed?");
    label.setBounds(35, 5, 100, 20);

    final Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setBounds(20, 35, 40, 25);
    okButton.setText("OK");

    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setBounds(70, 35, 40, 25);
    cancelButton.setText("Cancel");

    final boolean[] response = new boolean[1];
    response[0] = true;

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (event.widget == okButton) {
                response[0] = true;
            } else {
                response[0] = false;
            }
            dialog.close();
        }
    };

    okButton.addListener(SWT.Selection, listener);
    cancelButton.addListener(SWT.Selection, listener);

    Listener openerListener = new Listener() {
        public void handleEvent(Event event) {
            dialog.open();
        }
    };

    opener.addListener(SWT.Selection, openerListener);

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

    if (response[0]) {
        text.setText("You clicked OK");
    } else {
        text.setText("You clicked Cancel");
    }

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

From source file:MainClass.java

public static void main(String[] a) {

    final Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setSize(250, 200);// ww  w  .ja  v  a  2  s.c om

    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);

    final Browser browser = new Browser(shell, SWT.NONE);
    data = new FormData();
    data.top = new FormAttachment(controls);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    controls.setLayout(new GridLayout(6, 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());
        }
    });

    shell.setDefaultButton(button);

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

From source file:TextLayoutImageControl.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Embedding objects in text");
    final Image[] images = { new Image(display, 32, 32), new Image(display, 20, 40),
            new Image(display, 40, 20) };
    int[] colors = { SWT.COLOR_BLUE, SWT.COLOR_MAGENTA, SWT.COLOR_GREEN };
    for (int i = 0; i < images.length; i++) {
        GC gc = new GC(images[i]);
        gc.setBackground(display.getSystemColor(colors[i]));
        gc.fillRectangle(images[i].getBounds());
        gc.dispose();/* ww w .j a  v a  2  s .c om*/
    }

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Button");
    button.pack();
    String text = "Here is some text with a blue image \uFFFC, a magenta image \uFFFC, a green image \uFFFC, and a button: \uFFFC.";
    final int[] imageOffsets = { 36, 55, 72 };
    final TextLayout layout = new TextLayout(display);
    layout.setText(text);
    for (int i = 0; i < images.length; i++) {
        Rectangle bounds = images[i].getBounds();
        TextStyle imageStyle = new TextStyle(null, null, null);
        imageStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
        layout.setStyle(imageStyle, imageOffsets[i], imageOffsets[i]);
    }
    Rectangle bounds = button.getBounds();
    TextStyle buttonStyle = new TextStyle(null, null, null);
    buttonStyle.metrics = new GlyphMetrics(bounds.height, 0, bounds.width);
    final int buttonOffset = text.length() - 2;
    layout.setStyle(buttonStyle, buttonOffset, buttonOffset);

    shell.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event event) {
            GC gc = event.gc;
            Point margin = new Point(10, 10);
            layout.setWidth(shell.getClientArea().width - 2 * margin.x);
            layout.draw(event.gc, margin.x, margin.y);
            for (int i = 0; i < images.length; i++) {
                int offset = imageOffsets[i];
                int lineIndex = layout.getLineIndex(offset);
                FontMetrics lineMetrics = layout.getLineMetrics(lineIndex);
                Point point = layout.getLocation(offset, false);
                GlyphMetrics glyphMetrics = layout.getStyle(offset).metrics;
                gc.drawImage(images[i], point.x + margin.x,
                        point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent);
            }
            int lineIndex = layout.getLineIndex(buttonOffset);
            FontMetrics lineMetrics = layout.getLineMetrics(lineIndex);
            Point point = layout.getLocation(buttonOffset, false);
            GlyphMetrics glyphMetrics = layout.getStyle(buttonOffset).metrics;
            button.setLocation(point.x + margin.x,
                    point.y + margin.y + lineMetrics.getAscent() - glyphMetrics.ascent);
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    layout.dispose();
    for (int i = 0; i < images.length; i++) {
        images[i].dispose();
    }
    display.dispose();
}

From source file:Snippet21.java

public static void main(String[] args) {
    Display display = new Display();
    final Color red = display.getSystemColor(SWT.COLOR_RED);
    final Color blue = display.getSystemColor(SWT.COLOR_BLUE);
    Shell shell = new Shell(display);
    Button b = new Button(shell, SWT.PUSH);
    b.setBounds(10, 10, 100, 32);/*from   w w  w . j ava 2 s. co m*/
    b.setText("Button");
    shell.setDefaultButton(b);
    final Canvas c = new Canvas(shell, SWT.BORDER);
    c.setBounds(10, 50, 100, 32);
    c.addListener(SWT.Traverse, new Listener() {
        public void handleEvent(Event e) {
            switch (e.detail) {
            /* Do tab group traversal */
            case SWT.TRAVERSE_ESCAPE:
            case SWT.TRAVERSE_RETURN:
            case SWT.TRAVERSE_TAB_NEXT:
            case SWT.TRAVERSE_TAB_PREVIOUS:
            case SWT.TRAVERSE_PAGE_NEXT:
            case SWT.TRAVERSE_PAGE_PREVIOUS:
                e.doit = true;
                break;
            }
        }
    });
    c.addListener(SWT.FocusIn, new Listener() {
        public void handleEvent(Event e) {
            c.setBackground(red);
        }
    });
    c.addListener(SWT.FocusOut, new Listener() {
        public void handleEvent(Event e) {
            c.setBackground(blue);
        }
    });
    c.addListener(SWT.KeyDown, new Listener() {
        public void handleEvent(Event e) {
            System.out.println("KEY");
            for (int i = 0; i < 64; i++) {
                Color c1 = red, c2 = blue;
                if (c.isFocusControl()) {
                    c1 = blue;
                    c2 = red;
                }
                c.setBackground(c1);
                c.update();
                c.setBackground(c2);
            }
        }
    });
    Text t = new Text(shell, SWT.SINGLE | SWT.BORDER);
    t.setBounds(10, 85, 100, 32);

    Text r = new Text(shell, SWT.MULTI | SWT.BORDER);
    r.setBounds(10, 120, 100, 32);

    c.setFocus();
    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    errorIcon = display.getSystemImage(SWT.ICON_ERROR);
    Shell shell = new Shell(display);
    shell.setText("Snippet 363");
    shell.setLayout(new GridLayout(2, false));
    shell.setText("LiveRegion Test");

    icon = new Label(shell, SWT.NONE);
    icon.setLayoutData(new GridData(32, 32));

    liveLabel = new Text(shell, SWT.READ_ONLY);
    GC gc = new GC(liveLabel);
    Point pt = gc.textExtent(errorMessage);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    data.minimumWidth = (int) (pt.x + gc.getFontMetrics().getAverageCharacterWidth() * 2);
    gc.dispose();//  w  w  w.  ja  v a  2 s . co  m
    liveLabel.setLayoutData(data);
    liveLabel.setText("");
    liveLabel.getAccessible().addAccessibleAttributeListener(new AccessibleAttributeAdapter() {
        @Override
        public void getAttributes(AccessibleAttributeEvent e) {
            e.attributes = new String[] { "container-live", "polite", "live", "polite", "container-live-role",
                    "status", };
        }
    });

    final Label textFieldLabel = new Label(shell, SWT.NONE);
    textFieldLabel.setText("Type a number:");
    textFieldLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    final Text textField = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    final Button okButton = new Button(shell, SWT.PUSH);
    okButton.setText("OK");
    okButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false, 2, 1));
    okButton.setEnabled(false);

    textField.addModifyListener(e -> {
        boolean isNumber = false;
        String textValue = textField.getText();
        try {
            Integer.parseInt(textValue);
            isNumber = true;
            setMessageText(false, "Thank-you");
        } catch (NumberFormatException ex) {
            if (textValue.isEmpty()) {
                setMessageText(false, "");
            } else {
                setMessageText(true, "Error: Number expected.");
            }
        }
        okButton.setEnabled(isNumber);
    });

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

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

public static void main(String[] args) {

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 330");
    shell.setLayout(new GridLayout(BUTTONS_PER_ROW, true));

    final Browser browser;
    try {//w  ww.j  a  v a2  s. co  m
        browser = new Browser(shell, SWT.NONE);
    } catch (SWTError e) {
        System.out.println("Could not instantiate Browser: " + e.getMessage());
        display.dispose();
        return;
    }
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = BUTTONS_PER_ROW;
    browser.setLayoutData(data);

    {
        Button setHeaders = new Button(shell, SWT.PUSH);
        setHeaders.setText("Send custom headers");
        setHeaders.addListener(SWT.Selection,
                event -> browser.setUrl("http://www.ericgiguere.com/tools/http-header-viewer.html", null,
                        new String[] { "User-agent: SWT Browser", "Custom-header: this is just a demo" }));
    }

    {
        Button postTextPlain = new Button(shell, SWT.PUSH);
        postTextPlain.setText("Post data as 'text/plain'");
        postTextPlain.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post",
                "Plain text passed as postData", new String[] { "content-type: text/plain" }));
    }

    {
        Button postTextPlainUtf8 = new Button(shell, SWT.PUSH);
        postTextPlainUtf8.setText("Post data as 'text/plain' and specify encoding.");
        postTextPlainUtf8.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post",
                "Plain text passed as postData", new String[] { "content-type: text/plain; charset=UTF-8" }));
    }

    {
        Button postUrlEncoded = new Button(shell, SWT.PUSH);
        postUrlEncoded.setText("Post data with url encoding key=value");
        postUrlEncoded.addListener(SWT.Selection,
                event -> browser.setUrl("http://httpbin.org/post", "MyKey1=MyValue1&MyKey2=MyValue2",
                        new String[] { "content-type: application/x-www-form-urlencoded" }));
    }

    {
        Button postDataBugzilla = new Button(shell, SWT.PUSH);
        postDataBugzilla.setText("Send post data to bugzilla. url encoding is used as default");
        postDataBugzilla.addListener(SWT.Selection, event -> browser.setUrl(
                "https://bugs.eclipse.org/bugs/buglist.cgi",
                "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring",
                null));
    }

    {
        Button postDataBugzillaLongQuery = new Button(shell, SWT.PUSH);
        postDataBugzillaLongQuery.setText("Send post data to bugzilla. Very slow response");
        postDataBugzillaLongQuery.addListener(SWT.Selection,
                event -> browser.setUrl("https://bugs.eclipse.org/bugs/buglist.cgi",
                        "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW", null));
    }

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

From source file:Snippet134.java

public static void main(String[] args) {
    final Display display = new Display();
    // Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    // define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));//w w  w  .  j a  va 2s. c o  m
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] { 67, 50, 55, 105, 79, 105 });
    // define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    // add ability to move shell around
    Listener l = new Listener() {
        Point origin;

        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.MouseDown:
                origin = new Point(e.x, e.y);
                break;
            case SWT.MouseUp:
                origin = null;
                break;
            case SWT.MouseMove:
                if (origin != null) {
                    Point p = display.map(shell, null, e.x, e.y);
                    shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
        }
    };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    // add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            shell.close();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    region.dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 212");
    shell.setLayout(new GridLayout());
    styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    styledText.setText(text);/* w  ww  .ja  v  a2s . c om*/
    int offset = text.indexOf("\uFFFC", 0);
    addImage(display.getSystemImage(SWT.ICON_QUESTION), offset);
    offset = text.indexOf("\uFFFC", offset + 1);
    addImage(display.getSystemImage(SWT.ICON_INFORMATION), offset);

    // use a verify listener to dispose the images
    styledText.addVerifyListener(event -> {
        if (event.start == event.end)
            return;
        String text = styledText.getText(event.start, event.end - 1);
        int index = text.indexOf('\uFFFC');
        while (index != -1) {
            StyleRange style = styledText.getStyleRangeAtOffset(event.start + index);
            if (style != null) {
                Image image = (Image) style.data;
                if (image != null)
                    image.dispose();
            }
            index = text.indexOf('\uFFFC', index + 1);
        }
    });
    // draw images on paint event
    styledText.addPaintObjectListener(event -> {
        StyleRange style = event.style;
        Image image = (Image) style.data;
        if (!image.isDisposed()) {
            int x = event.x;
            int y = event.y + event.ascent - style.metrics.ascent;
            event.gc.drawImage(image, x, y);
        }
    });
    styledText.addListener(SWT.Dispose, event -> {
        StyleRange[] styles = styledText.getStyleRanges();
        for (int i = 0; i < styles.length; i++) {
            StyleRange style = styles[i];
            if (style.data != null) {
                Image image = (Image) style.data;
                if (image != null)
                    image.dispose();
            }
        }
    });
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Add Image");
    button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    button.addListener(SWT.Selection, event -> {
        FileDialog dialog = new FileDialog(shell);
        String filename = dialog.open();
        if (filename != null) {
            try {
                Image image = new Image(display, filename);
                int offset1 = styledText.getCaretOffset();
                styledText.replaceTextRange(offset1, 0, "\uFFFC");
                addImage(image, offset1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    shell.setSize(400, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    //Shell must be created with style SWT.NO_TRIM
    final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
    shell.setText("Snippet 134");
    shell.setBackground(display.getSystemColor(SWT.COLOR_RED));
    //define a region that looks like a key hole
    Region region = new Region();
    region.add(circle(67, 67, 67));/*from w  w w  . ja v a2  s.  c  o m*/
    region.subtract(circle(20, 67, 50));
    region.subtract(new int[] { 67, 50, 55, 105, 79, 105 });
    //define the shape of the shell using setRegion
    shell.setRegion(region);
    Rectangle size = region.getBounds();
    shell.setSize(size.width, size.height);
    //add ability to move shell around
    Listener l = new Listener() {
        /** The x/y of the MouseDown, relative to top-left of the shell. */
        Point origin;

        @Override
        public void handleEvent(Event e) {
            switch (e.type) {
            case SWT.MouseDown:
                Point point = shell.toDisplay(e.x, e.y);
                Point loc = shell.getLocation();
                origin = new Point(point.x - loc.x, point.y - loc.y);
                break;
            case SWT.MouseUp:
                origin = null;
                break;
            case SWT.MouseMove:
                if (origin != null) {
                    Point p = display.map(shell, null, e.x, e.y);
                    shell.setLocation(p.x - origin.x, p.y - origin.y);
                }
                break;
            }
        }
    };
    shell.addListener(SWT.MouseDown, l);
    shell.addListener(SWT.MouseUp, l);
    shell.addListener(SWT.MouseMove, l);
    //add ability to close shell
    Button b = new Button(shell, SWT.PUSH);
    b.setBackground(shell.getBackground());
    b.setText("close");
    b.pack();
    b.setLocation(10, 68);
    b.addListener(SWT.Selection, e -> shell.close());
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    region.dispose();
    display.dispose();
}