[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Problem with RowLayout wrap inside a FormLayout?

What version of Eclipse/SWT are you running?  In Eclipse 3.1 M3 or later the wrapping should just work without messing with the width value.
 
The following works for me in 3.0:
 
public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new FormLayout());
        final Composite rightPanel = new Composite(shell, SWT.BORDER);
        rightPanel.setLayout(new RowLayout());
        for (int i = 0; i < 15; i++) {
                Button b = new Button(rightPanel, SWT.PUSH);
                b.setText("Button "+i);
        }
        FormData data = "" FormData();
        data.left = new FormAttachment(0, 10);
        data.top =  new FormAttachment(0, 10);
        rightPanel.setLayoutData(data);
        final Composite leftPanel = new Composite(shell, SWT.BORDER);
        data = "" FormData();
        data.left = new FormAttachment(0, 10);
        data.right = new FormAttachment(100, -10);
        data.top =  new FormAttachment(rightPanel, 10);
        data.bottom = new FormAttachment(100, -10);
        leftPanel.setLayoutData(data);
       
        shell.addListener(SWT.Resize, new Listener() {
                public void handleEvent(Event e) {
                        Rectangle area = shell.getClientArea();
            FormData data = ""
            data.width = area.width - 20;
            shell.layout(true);
                }
        });
        shell.open();
        while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                        display.sleep();
        }
        display.dispose();
}
 
The code above works in 3.1 but it can also be simplified to:
 
public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new FormLayout());
        final Composite rightPanel = new Composite(shell, SWT.BORDER);
        rightPanel.setLayout(new RowLayout());
        for (int i = 0; i < 15; i++) {
                Button b = new Button(rightPanel, SWT.PUSH);
                b.setText("Button "+i);
        }
        FormData data = "" FormData();
        data.left = new FormAttachment(0, 10);
        data.top =  new FormAttachment(0, 10);
        data.right = new FormAttachment(100, -10);
        rightPanel.setLayoutData(data);
        final Composite leftPanel = new Composite(shell, SWT.BORDER);
        data = "" FormData();
        data.left = new FormAttachment(0, 10);
        data.right = new FormAttachment(100, -10);
        data.top =  new FormAttachment(rightPanel, 10);
        data.bottom = new FormAttachment(100, -10);
        leftPanel.setLayoutData(data);
        shell.open();
        while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                        display.sleep();
        }
        display.dispose();
}

This seems very similar to an earlier post regarding a problem with RowLayout wrap inside a GridLayout, but the same solution didn't work for me because FormData does not have a widthHint.

Briefly, I have a composite which has a FormLayout. I want one component of it to be a "button holder" composite with a rowLayout (horizontal), and I want it to take up just enough room to hold its buttons, and that might be one or two or three rows, depending on the width of the overall composite. I want the other component of the composite to  be the largest size it can be (it's a drawing), taking up "the rest" of the room.

I attach the "button composite" to the left, top, and right of the Composite holding it, and I attach the "picture" to the left, right, and bottom of the Composite holding it, plus I attach its top to the "buttonComposite". This does just what I want *except* that the "button Composite" does not wrap; it clips the buttons instead, and remains one row in height at all times.

As I mentioned, FormData does not have a widthHint, so I experimented with using "width" instead like so (modifying the workaround given in the earlier posting):  however in this case, while it did wrap, the space it takes up vertically did not change (that is, the "picture" did not get any smaller, so it clipped off the buttons)

         shell.addListener(SWT.Resize, new Listener() {
            public void handleEvent(Event e) {
             Rectangle area = shell.getClientArea();
             FormData data = "">
             data.width = area.width;
             shell.layout(true);
            }
           });

Is it possible to do what I want, that is, have the RowLayout "button Composite" wrap properly?