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

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

Introduction

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

Prototype

public Point computeSize(int wHint, int hHint) 

Source Link

Document

Returns the preferred size of the receiver.

Usage

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 278");
    shell.setBounds(10, 10, 300, 100);//from w w w. j ava2 s . c  om
    shell.setLayout(new FillLayout());
    final Label label = new Label(shell, SWT.NONE);
    label.setText("resize the Shell then hover over this Label");
    label.addListener(SWT.MouseEnter, event -> {
        Point requiredSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point labelSize = label.getSize();
        boolean fullyVisible = requiredSize.x <= labelSize.x && requiredSize.y <= labelSize.y;
        System.out.println("Label is fully visible: " + fullyVisible);
        label.setToolTipText(fullyVisible ? null : label.getText());
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:FormLayoutDialogDemo.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("Some text for your dialog.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1", "Item2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Ok");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;/*from  w w  w .j ava 2  s.c o m*/
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            labelData.width = rect.width - insetX * 2;
            shell.layout();
        }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

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

}

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

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 65");
    Label label = new Label(shell, SWT.WRAP);
    label.setText("This is a long text string that will wrap when the dialog is resized.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems("Item 1", "Item 2");
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("OK");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;//from   w w  w .  ja  v  a2  s.c  om
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, e -> {
        Rectangle rect = shell.getClientArea();
        labelData.width = rect.width - insetX * 2;
        shell.layout();
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

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

From source file:Snippet65.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("This is a long text string that will wrap when the dialog is resized.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1", "Item2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("Ok");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;//w  w  w.  j  a v a  2s  .  c o m
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            labelData.width = rect.width - insetX * 2;
            shell.layout();
        }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

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

From source file:DialogLayoutDemo.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    Label label = new Label(shell, SWT.WRAP);
    label.setText("This is a long text string that will wrap when the dialog is resized.");
    List list = new List(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    list.setItems(new String[] { "Item 1", "Item 2" });
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("OK");
    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("Cancel");

    final int insetX = 4, insetY = 4;
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = insetX;//from   www . ja v a 2 s  .  c om
    formLayout.marginHeight = insetY;
    shell.setLayout(formLayout);

    Point size = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    final FormData labelData = new FormData(size.x, SWT.DEFAULT);
    labelData.left = new FormAttachment(0, 0);
    labelData.right = new FormAttachment(100, 0);
    label.setLayoutData(labelData);
    shell.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            Rectangle rect = shell.getClientArea();
            labelData.width = rect.width - insetX * 2;
            shell.layout();
        }
    });

    FormData button2Data = new FormData();
    button2Data.right = new FormAttachment(100, -insetX);
    button2Data.bottom = new FormAttachment(100, 0);
    button2.setLayoutData(button2Data);

    FormData button1Data = new FormData();
    button1Data.right = new FormAttachment(button2, -insetX);
    button1Data.bottom = new FormAttachment(100, 0);
    button1.setLayoutData(button1Data);

    FormData listData = new FormData();
    listData.left = new FormAttachment(0, 0);
    listData.right = new FormAttachment(100, 0);
    listData.top = new FormAttachment(label, insetY);
    listData.bottom = new FormAttachment(button2, -insetY);
    list.setLayoutData(listData);

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