Hi,

I'm fairly new to using layouts, and I have scoured plenty of tutorials, but I cannot find anything that handles this situation.

*Note. I do not want to use setBounds, I want to be decided based on the controls text length.

I am just trying to create a simple application that has a label and a button (button will change to another control, but works the same for the example). I want the application window width to be determined by the width of the button (set to grab as much as it needs horizontally). I want the label to be above the button, and to wrap its text, but not to grab horizontally past what the button needs.

Java Code:
------------------------------------------------|
|  -------------------------------------------- |
|  | This is the label text that will wrap    | |
|  | because of the app width ....            | |
|  -------------------------------------------- |
|  -------------------------------------------- |
|  | Button: want this 2 determine width .... | |
|  -------------------------------------------- |
-------------------------------------------------


I have tried to tell the composite to grab vertical, as well as the shell. I also have tried using the widthhint by setting it to 0. This works initially. But the form height will be set as if the label was 1 line and cut off part of the button height, until you resize the window, then it will extend to include the text and the button.

I have this code to try to do it.


Java Code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
 
public class TestApp {
 
    public static void main(String[] args) throws Exception {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());
        shell.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
 
        Composite c = new Composite(shell, SWT.NONE);
        c.setLayout(new GridLayout());
        c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
        Label label = new Label(c, SWT.WRAP | SWT.READ_ONLY);
        label.setText("This is some really long text that will fill up the label. "
                + "This text will be longer than the button text, (doesn't have to be a button). "
                + "So I hope this is enough text to make it longer than the button.");
 
        GridData glabel = new GridData(SWT.FILL, SWT.FILL, false, false);// , true, false);
        glabel.widthHint = 0; // this way it will be excluded from computing the app width
        label.setLayoutData(glabel);
 
        Button button = new Button(c, SWT.PUSH);
        button.setText("This is some really long text that will determine the button width "
                + "that I want to control the page starting width by." + "I sure hope it works. ");
 
        c.pack();
        shell.pack();
 
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
 
    }
}