Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Simple FormLayout question
Simple FormLayout question [message #460950] Mon, 12 September 2005 22:23 Go to next message
Eclipse UserFriend
Originally posted by: ondrej.kucera.centrum.cz

------------ek49XoUjSp799uDOVR0eM1
Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
Content-Transfer-Encoding: 8bit

Hello,

I'm trying to have following layout: three composites vertically filling
the whole shell, where composite1 has its height taken from its content
and composite2 and composite3 equally share the rest of the space. What I
can't achieve is changing heights of composite2 and composite3 when height
of composite1 changes (either by gaining some content or by user changing
size of the shell) - so that they still take 50% and 50% of the remaining
space. I think the right way is catching SWT.Resize event on composite1
but I'm not quite sure what to do in the handler - I've tried a couple of
things but none of them have worked. I hope the code snippet will help to
understand what I mean.

Regards, Ondrej
------------ek49XoUjSp799uDOVR0eM1
Content-Disposition: attachment; filename=ResizeSnippet.java
Content-Type: application/octet-stream; name=ResizeSnippet.java
Content-Transfer-Encoding: Base64

aW1wb3J0IG9yZy5lY2xpcHNlLnN3dC4qOwppbXBvcnQgb3JnLmVjbGlwc2Uu c3d0
LmN1c3RvbS4qOwppbXBvcnQgb3JnLmVjbGlwc2Uuc3d0LmV2ZW50cy4qOwpp bXBv
cnQgb3JnLmVjbGlwc2Uuc3d0LmxheW91dC4qOwppbXBvcnQgb3JnLmVjbGlw c2Uu
c3d0LndpZGdldHMuKjsKCnB1YmxpYyBjbGFzcyBSZXNpemVTbmlwcGV0IHsK ICAg
IHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKCURp c3Bs
YXkgZGlzcGxheSA9IG5ldyBEaXNwbGF5KCk7CglTaGVsbCBzaGVsbCA9IG5l dyBT
aGVsbChkaXNwbGF5KTsKCXNoZWxsLnNldFRleHQoIlJlc2l6ZVNuaXBwZXQi KTsK
CXNoZWxsLnNldExheW91dChuZXcgRmlsbExheW91dCgpKT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dG9u
KGxlZnRDb21wb3NpdGUsIFNXVC5QVVNIKTsKCWJ1dHRvbi5zZXRUZXh0KCJB ZGQg
MjAgbGFiZWxzIik7CglidXR0b24ucGFjaygpOwoJYnV0dG9uLmFkZFNlbGVj dGlv
bkxpc3RlbmVyKG5ldyBTZWxlY3Rpb25BZGFwdGVyKCkgewoJCXB1YmxpYyB2 b2lk
IHdpZGdldFNlbGVjdGVkKFNlbGVjdGlvbkV2ZW50IGV2ZW50KSB7CgkJICAg IGZv
ciAoaW50IGkgPSAwOyBpIDwgMjA7IGkrKykgbmV3IExhYmVsKGNvbXBvc2l0 ZTEs
IFNXVC5OT05FKS5zZXRUZXh0KCJMYWJlbF8iICsgaSk7CgkJICAgIGNvbXBv c2l0
ZTEubGF5b3V0KCk7CgkJICAgIHJpZ2h0Q29tcG9zaXRlLmxheW91dCgpOwoJ CX0K
CSAgICB9KTsKCWZvcm0uc2V0V2VpZ2h0cyhuZXcgaW50W10gezMwLCA3MH0p OwoJ
c2hlbGwuc2V0U2l6ZSg4MDAsIDYwMCk7CglzaGVsbC5vcGVuKCk7Cgl3aGls ZSAo
IXNoZWxsLmlzRGlzcG9zZWQoKSkgewoJICAgIGlmICghZGlzcGxheS5yZWFk QW5k
RGlzcGF0Y2goKSkgewoJCWRpc3BsYXkuc2xlZXAoKTsKCSAgICB9Cgl9Cglk aXNw
bGF5LmRpc3Bvc2UoKTsKICAgIH0KfQo=

------------ek49XoUjSp799uDOVR0eM1--
Re: Simple FormLayout question [message #460971 is a reply to message #460950] Tue, 13 September 2005 13:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ddana78ar.yahoo.com.ar

------=_Part_372_6712913.1126617157753
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I don't know if it's that you want, but I hope that.
Best regards.
------=_Part_372_6712913.1126617157753
Content-Type: application/octet-stream; name=ResizeSnippet.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=ResizeSnippet.java

/*
* Created on 12-sep-2005
* by DDana
*/
package testing;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class ResizeSnippet {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("ResizeSnippet");
shell.setLayout(new FillLayout());

SashForm form = new SashForm(shell, SWT.HORIZONTAL);

Composite leftComposite = new Composite(form, SWT.BORDER);
leftComposite.setLayout(new RowLayout());

final Composite rightComposite = new Composite(form, SWT.BORDER);
rightComposite.setLayout(new FormLayout());

final Composite composite1 = new Composite(rightComposite, SWT.BORDER);
composite1.setLayout(new RowLayout());
FormData composite1FormData = new FormData();
composite1FormData.left = new FormAttachment(0, 4);
composite1FormData.right = new FormAttachment(100, -4);
composite1FormData.top = new FormAttachment(0, 4);
composite1.setLayoutData(composite1FormData);
composite1.setLayout(new RowLayout());

Composite compositeTheNEW = new Composite(rightComposite, SWT.NONE);
FormData compositeFormDataTheNEW = new FormData();
compositeFormDataTheNEW.left = new FormAttachment(0, 0);
compositeFormDataTheNEW.right = new FormAttachment(100, 0);
compositeFormDataTheNEW.top = new FormAttachment(composite1, 0);
compositeFormDataTheNEW.bottom = new FormAttachment(100, 0);
compositeTheNEW.setLayoutData(compositeFormDataTheNEW);
compositeTheNEW.setLayout(new FormLayout());

Composite composite2 = new Composite(compositeTheNEW, SWT.BORDER);
FormData composite2FormData = new FormData();
composite2FormData.left = new FormAttachment(0, 4);
composite2FormData.right = new FormAttachment(100, -4);
composite2FormData.top = new FormAttachment(0, 4);
composite2FormData.bottom = new FormAttachment(50, -4);
composite2.setLayoutData(composite2FormData);
//composite2.setLayout(new RowLayout());

Composite composite3 = new Composite(compositeTheNEW, SWT.BORDER);
FormData composite3FormData = new FormData();
composite3FormData.left = new FormAttachment(0, 4);
composite3FormData.right = new FormAttachment(100, -4);
composite3FormData.top = new FormAttachment(composite2, 4);
composite3FormData.bottom = new FormAttachment(100, -4);
composite3.setLayoutData(composite3FormData);

Button button = new Button(leftComposite, SWT.PUSH);
button.setText("Add 20 labels");
button.pack();
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
for (int i = 0; i < 20; i++) new Label(composite1, SWT.NONE).setText("Label_" + i);
composite1.layout();
rightComposite.layout();
}
});

form.setWeights(new int[] {30, 70});

shell.setSize(800, 600);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}


------=_Part_372_6712913.1126617157753--
Re: Simple FormLayout question [message #460988 is a reply to message #460971] Tue, 13 September 2005 22:24 Go to previous message
Eclipse UserFriend
Originally posted by: ondrej.kucera.centrum.cz

Hello,

yes, that's what I meant, thanks, I didn't think of it that way. I still
don't know what's wrong with trying to catch the resize event and re-set
top and bottom formattachments for composite2 and composite3 though. But
never mind that now.

Regards, Ondrej


On Tue, 13 Sep 2005 15:10:15 +0200, ddana <ddana78ar@yahoo.com.ar> wrote:

> I don't know if it's that you want, but I hope that.
> Best regards.
Previous Topic:ISelectionListener question - how to register?
Next Topic:Tree.expandAll
Goto Forum:
  


Current Time: Fri Apr 26 11:25:03 GMT 2024

Powered by FUDForum. Page generated in 0.03355 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top