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

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

Introduction

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

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

Sets the receiver's size and location to the rectangular area specified by the arguments.

Usage

From source file:WrapStyleLabel.java

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

    String text = "This is a long long long long long long long text.";

    Label labelNoWrap = new Label(shell, SWT.BORDER);
    labelNoWrap.setText(text);/*from   ww  w  .  ja v a 2  s  .c om*/
    labelNoWrap.setBounds(10, 10, 100, 100);

    Label labelWrap = new Label(shell, SWT.WRAP | SWT.BORDER);
    labelWrap.setText(text);
    labelWrap.setBounds(120, 10, 100, 100);

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

From source file:Snippet153.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setBounds(10, 10, 200, 200);//w  w  w.  j a va2 s .  c  o  m
    final ToolBar bar = new ToolBar(shell, SWT.BORDER);
    bar.setBounds(10, 10, 150, 50);
    final Label statusLine = new Label(shell, SWT.BORDER);
    statusLine.setBounds(10, 90, 150, 30);
    new ToolItem(bar, SWT.NONE).setText("item 1");
    new ToolItem(bar, SWT.NONE).setText("item 2");
    new ToolItem(bar, SWT.NONE).setText("item 3");
    bar.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            ToolItem item = bar.getItem(new Point(e.x, e.y));
            String name = "";
            if (item != null) {
                name = item.getText();
            }
            if (!statusText.equals(name)) {
                statusLine.setText(name);
                statusText = name;
            }
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 153");
    shell.setBounds(10, 10, 200, 200);//www  . j a  va 2s .c  om
    final ToolBar bar = new ToolBar(shell, SWT.BORDER);
    bar.setBounds(10, 10, 150, 50);
    final Label statusLine = new Label(shell, SWT.BORDER);
    statusLine.setBounds(10, 90, 150, 30);
    new ToolItem(bar, SWT.NONE).setText("item 1");
    new ToolItem(bar, SWT.NONE).setText("item 2");
    new ToolItem(bar, SWT.NONE).setText("item 3");
    bar.addMouseMoveListener(e -> {
        ToolItem item = bar.getItem(new Point(e.x, e.y));
        String name = "";
        if (item != null) {
            name = item.getText();
        }
        if (!statusText.equals(name)) {
            statusLine.setText(name);
            statusText = name;
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {

    Shell shell = new Shell(new Display());
    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
    dialog.setText("Delete File");
    dialog.setSize(250, 150);//from w  ww.j a  v  a  2  s. com

    final Button buttonOK = new Button(dialog, SWT.PUSH);
    buttonOK.setText("OK");
    buttonOK.setBounds(20, 55, 80, 25);

    Button buttonCancel = new Button(dialog, SWT.PUSH);
    buttonCancel.setText("Cancel");
    buttonCancel.setBounds(120, 55, 80, 25);

    final Label label = new Label(dialog, SWT.NONE);
    label.setText("Delete the file?");
    label.setBounds(20, 15, 100, 20);

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (event.widget == buttonOK) {
                System.out.println("OK");
            } else {
                System.out.println("Cancel");
            }
            dialog.close();
        }
    };

    buttonOK.addListener(SWT.Selection, listener);
    buttonCancel.addListener(SWT.Selection, listener);

    dialog.open();

}

From source file:MainClass.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sliders");
    shell.setSize(300, 200);/*w  ww.ja v a 2s.c o  m*/

    final Label label = new Label(shell, SWT.NONE);
    label.setText("Move the slider");
    label.setBounds(0, 20, 150, 15);

    final Slider slider = new Slider(shell, SWT.HORIZONTAL);
    slider.setBounds(0, 40, 200, 20);

    final Text text = new Text(shell, SWT.BORDER);
    text.setBounds(0, 100, 200, 25);

    slider.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            String outString = "Event: SWT.NONE";
            switch (event.detail) {
            case SWT.ARROW_DOWN:
                outString = "Event: SWT.ARROW_DOWN";
                break;
            case SWT.ARROW_UP:
                outString = "Event: SWT.ARROW_UP";
                break;
            case SWT.DRAG:
                outString = "Event: SWT.DRAG";
                break;
            case SWT.END:
                outString = "Event: SWT.END";
                break;
            case SWT.HOME:
                outString = "Event: SWT.HOME";
                break;
            case SWT.PAGE_DOWN:
                outString = "Event: SWT.PAGE_DOWN";
                break;
            case SWT.PAGE_UP:
                outString = "Event: SWT.PAGE_UP";
                break;
            }
            outString += " Position: " + slider.getSelection();
            text.setText(outString);
        }
    });

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

From source file:DialogClass.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Dialog Example");
    shell.setSize(300, 200);/*from w  w w  . jav a2  s.c  om*/
    shell.open();

    final Button button = new Button(shell, SWT.PUSH);
    button.setText("Delete File");
    button.setBounds(20, 40, 80, 25);

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

    final Shell dialog = new Shell(shell, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
    dialog.setText("Delete File");
    dialog.setSize(250, 150);

    final Button buttonOK = new Button(dialog, SWT.PUSH);
    buttonOK.setText("OK");
    buttonOK.setBounds(20, 55, 80, 25);

    Button buttonCancel = new Button(dialog, SWT.PUSH);
    buttonCancel.setText("Cancel");
    buttonCancel.setBounds(120, 55, 80, 25);

    final Label label = new Label(dialog, SWT.NONE);
    label.setText("Delete the file?");
    label.setBounds(20, 15, 100, 20);

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (event.widget == buttonOK) {
                deleteFlag = true;
            } else {
                deleteFlag = false;
            }
            dialog.close();
        }
    };

    buttonOK.addListener(SWT.Selection, listener);
    buttonCancel.addListener(SWT.Selection, listener);

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

    button.addListener(SWT.Selection, buttonListener);

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

    if (deleteFlag) {
        text.setText("File deleted.");
    } else {
        text.setText("File not deleted.");
    }

    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);/*from w  w w  . ja  va2s .  com*/
    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:EventListenerGeneral.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER);

    shell.setLayout(new GridLayout());

    Listener listener = new MouseEnterExitListener();

    label.setText("Point your cursor here ...");
    label.setBounds(30, 30, 200, 30);

    label.addListener(SWT.MouseEnter, listener);
    label.addListener(SWT.MouseExit, listener);

    shell.setSize(260, 120);/*  w  w  w  . j a  v  a  2s .c  o  m*/
    shell.open();

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

From source file:MouseTrackAdapter.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.SHADOW_IN | SWT.CENTER);

    shell.setLayout(new GridLayout());

    MouseTrackAdapter listener = new MouseEnterExitListener();

    label.setText("Point your cursor here ...");
    label.setBounds(30, 30, 200, 30);

    label.addMouseTrackListener(listener);

    shell.setSize(260, 120);// ww  w  .  j ava  2 s .  com
    shell.open();

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

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);/*ww w. j ava 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();
}