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

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

Introduction

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

Prototype

public void setLocation(int x, int y) 

Source Link

Document

Sets the receiver's location to the point specified by the arguments which are relative to the receiver's parent (or its display if its parent is null), unless the receiver is a shell.

Usage

From source file:Snippet4.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Open Dialog ...");
    b.pack();/*w w w  . ja v  a  2  s  .c  o  m*/
    b.setLocation(10, 10);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent se) {
            Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
            dialog.addListener(SWT.Traverse, new Listener() {
                public void handleEvent(Event e) {
                    if (e.detail == SWT.TRAVERSE_ESCAPE) {
                        e.doit = false;
                    }
                }
            });
            dialog.open();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 103");
    shell.setBounds(10, 10, 200, 240);/*  w w  w.j  ava 2 s .c om*/
    Table table = new Table(shell, SWT.NONE);
    Rectangle clientArea = shell.getClientArea();
    table.setBounds(clientArea.x + 10, clientArea.y + 10, 160, 160);

    final TableItem[] items = new TableItem[4];
    for (int i = 0; i < 4; i++) {
        new TableColumn(table, SWT.NONE).setWidth(40);
    }
    for (int i = 0; i < 4; i++) {
        items[i] = new TableItem(table, SWT.NONE);
        populateItem(items[i]);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change");
    button.pack();
    button.setLocation(10, 180);
    button.addListener(SWT.Selection, event -> {
        for (int i = 0; i < 4; i++) {
            populateItem(items[i]);
        }
    });

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

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

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

    final Table table = new Table(shell, SWT.MULTI);
    table.setLinesVisible(true);//from   ww w .  j  a  v  a 2  s .c o m
    table.setBounds(10, 10, 100, 100);
    for (int i = 0; i < 9; i++) {
        new TableItem(table, SWT.NONE).setText("item" + i);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();
    button.setLocation(10, 140);
    button.addListener(SWT.Selection, event -> {
        Point tableSize = table.getSize();
        GC gc = new GC(table);
        final Image image = new Image(display, tableSize.x, tableSize.y);
        gc.copyArea(image, 0, 0);
        gc.dispose();

        Shell popup = new Shell(shell);
        popup.setText("Image");
        popup.addListener(SWT.Close, e -> image.dispose());

        Canvas canvas = new Canvas(popup, SWT.NONE);
        canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10);
        canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
        popup.pack();
        popup.open();
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TableItemUpdateText.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setBounds(10, 10, 200, 240);/*ww w  .j a va  2  s.  co  m*/
    Table table = new Table(shell, SWT.NONE);
    table.setBounds(10, 10, 160, 160);

    final TableItem[] items = new TableItem[4];
    for (int i = 0; i < 4; i++) {
        new TableColumn(table, SWT.NONE).setWidth(40);
    }
    for (int i = 0; i < 4; i++) {
        items[i] = new TableItem(table, SWT.NONE);
        populateItem(items[i]);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change");
    button.pack();
    button.setLocation(10, 180);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            for (int i = 0; i < 4; i++) {
                populateItem(items[i]);
            }
        }
    });

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

From source file:ScreenshotCaptureGC.java

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

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();/*  www.  jav  a 2  s.co m*/
    button.setLocation(10, 140);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            GC gc = new GC(display);
            final Image image = new Image(display, 400, 400);
            gc.copyArea(image, 0, 0);
            gc.dispose();

            Shell popup = new Shell(shell);
            popup.setText("Image");
            popup.addListener(SWT.Close, new Listener() {
                public void handleEvent(Event e) {
                    image.dispose();
                }
            });

            Canvas canvas = new Canvas(popup, SWT.NONE);
            canvas.setBounds(10, 10, 400 + 10, 400 + 10);
            canvas.addPaintListener(new PaintListener() {
                public void paintControl(PaintEvent e) {
                    e.gc.drawImage(image, 0, 0);
                }
            });
            popup.pack();
            popup.open();
        }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 4");
    Button b = new Button(shell, SWT.PUSH);
    b.setText("Open Dialog ...");
    b.pack();/*from   www  .jav  a  2s . c  o m*/
    Rectangle clientArea = shell.getClientArea();
    b.setLocation(clientArea.x + 10, clientArea.y + 10);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);
        dialog.addListener(SWT.Traverse, t -> {
            if (t.detail == SWT.TRAVERSE_ESCAPE) {
                t.doit = false;
            }
        });
        dialog.open();
    }));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:CaptureWidgetImageGC.java

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

    final Table table = new Table(shell, SWT.MULTI);
    table.setLinesVisible(true);/*from   w  ww.j ava  2  s . c  om*/
    table.setBounds(10, 10, 100, 100);
    for (int i = 0; i < 9; i++) {
        new TableItem(table, SWT.NONE).setText("item" + i);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();
    button.setLocation(10, 140);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            Point tableSize = table.getSize();
            GC gc = new GC(table);
            final Image image = new Image(display, tableSize.x, tableSize.y);
            gc.copyArea(image, 0, 0);
            gc.dispose();

            Shell popup = new Shell(shell);
            popup.setText("Image");
            popup.addListener(SWT.Close, new Listener() {
                public void handleEvent(Event e) {
                    image.dispose();
                }
            });

            Canvas canvas = new Canvas(popup, SWT.NONE);
            canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10);
            canvas.addPaintListener(new PaintListener() {
                public void paintControl(PaintEvent e) {
                    e.gc.drawImage(image, 0, 0);
                }
            });
            popup.pack();
            popup.open();
        }
    });
    shell.pack();
    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 ava  2  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() {
        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.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 .  j  a v a2  s. co 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();
}

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

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 225");
    Image image = null;// www. j  a v a 2 s . c  om
    final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage(
            "Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");
    Tray tray = display.getSystemTray();
    if (tray != null) {
        TrayItem item = new TrayItem(tray, SWT.NONE);
        image = display.getSystemImage(SWT.ICON_INFORMATION);
        item.setImage(image);
        tip.setText("Notification from a tray item");
        item.setToolTip(tip);
    } else {
        tip.setText("Notification from anywhere");
        tip.setLocation(400, 400);
    }
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Press for balloon tip");
    button.addListener(SWT.Selection, event -> tip.setVisible(true));
    Rectangle clientArea = shell.getClientArea();
    button.setLocation(clientArea.x, clientArea.y);
    button.pack();
    shell.setBounds(50, 50, 300, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (image != null)
        image.dispose();
    display.dispose();
}