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

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

Introduction

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

Prototype

public void setSize(Point size) 

Source Link

Document

Sets the receiver's size to the point specified by the argument.

Usage

From source file:ControlSizeSetting.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setSize(150, 150);/*from  w w w. j a va2s  .  c om*/
    final Cursor[] cursor = new Cursor[1];
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change cursor");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    button.setSize(size);

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (cursor[0] != null)
        cursor[0].dispose();
    display.dispose();
}

From source file:Snippet118.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setSize(150, 150);//from  www  .  j av a  2 s . co  m
    final Cursor[] cursor = new Cursor[1];
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change cursor");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    button.setSize(size);
    button.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            FileDialog dialog = new FileDialog(shell);
            dialog.setFilterExtensions(new String[] { "*.ico", "*.gif", "*.*" });
            String name = dialog.open();
            if (name == null)
                return;
            ImageData image = new ImageData(name);
            Cursor oldCursor = cursor[0];
            cursor[0] = new Cursor(display, image, 0, 0);
            shell.setCursor(cursor[0]);
            if (oldCursor != null)
                oldCursor.dispose();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (cursor[0] != null)
        cursor[0].dispose();
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 118");
    shell.setSize(150, 150);/*ww w .  j a  v a2 s. c  o  m*/
    final Cursor[] cursor = new Cursor[1];
    Button button = new Button(shell, SWT.PUSH);
    button.setText("Change cursor");
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    button.setSize(size);
    button.addListener(SWT.Selection, e -> {
        FileDialog dialog = new FileDialog(shell);
        dialog.setFilterExtensions(new String[] { "*.ico", "*.gif", "*.*" });
        String name = dialog.open();
        if (name == null)
            return;
        ImageData image = new ImageData(name);
        Cursor oldCursor = cursor[0];
        cursor[0] = new Cursor(display, image, 0, 0);
        shell.setCursor(cursor[0]);
        if (oldCursor != null)
            oldCursor.dispose();
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (cursor[0] != null)
        cursor[0].dispose();
    display.dispose();
}