| [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(); }
|