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

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

Introduction

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

Prototype

public Point getSize() 

Source Link

Document

Returns a point describing the receiver's size.

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);/* ww  w.ja va  2 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:CoolBarExamples.java

public CoolBarExamples() {
    shell.setLayout(new GridLayout());

    final CoolBar coolBar = new CoolBar(shell, SWT.NONE);

    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // cool item with a text field.
    CoolItem textItem = new CoolItem(coolBar, SWT.NONE);

    Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN);
    text.setText("TEXT");
    text.pack();//w  w w  .j av  a 2s  . com

    Point size = text.getSize();
    textItem.setControl(text);
    textItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a label.
    CoolItem labelItem = new CoolItem(coolBar, SWT.NONE);

    Label label = new Label(coolBar, SWT.NONE);
    label.setText("LABEL");
    label.pack();

    size = label.getSize();
    labelItem.setControl(label);
    labelItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a button.
    CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN);

    Composite composite = new Composite(coolBar, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    button1.pack();

    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");
    button2.pack();

    composite.pack();

    size = composite.getSize();
    buttonItem.setControl(composite);
    buttonItem.setSize(buttonItem.computeSize(size.x, size.y));

    //      // Test cool item adding method.
    //      Label label2 = new Label(coolBar, SWT.NONE);
    //      label2.setText("label2");
    //      addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar);

    try {
        setState(coolBar, new File("coolbar.state"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    shell.addListener(SWT.Close, new Listener() {
        public void handleEvent(Event event) {
            try {
                saveState(coolBar, new File("coolbar.state"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    shell.setSize(300, 120);
    // shell.pack();
    shell.open();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}