Nested SWT Layouts

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Nested SWT Layouts

Postby cochand » Wed Jul 06, 2005 1:35 pm

Hi,
I'm building an SWT application that has a simple and constant left side that takes up 1/3 of the window, and a more compex and varying right side that takes up 2/3 of the window.

It seems that a good approach to this would be to nest SWT Layouts, possibly with a ColumnLayout as the base. The left column would contain the JFace TreeViewer and the right column would contain a GridLayout.

It seems impossible to nest SWT Layouts in WindowBuilderPro, and I see very few online references to nesting SWT Layouts. What would you suggest?

Thanks,
Jeff
cochand
 
Posts: 17
Joined: Wed Jul 06, 2005 1:20 pm

Re: Nested SWT Layouts

Postby Eric Clayberg » Thu Jul 07, 2005 3:45 am

cochand wrote:It seems that a good approach to this would be to nest SWT Layouts, possibly with a ColumnLayout as the base. The left column would contain the JFace TreeViewer and the right column would contain a GridLayout. It seems impossible to nest SWT Layouts in WindowBuilderPro, and I see very few online references to nesting SWT Layouts.

Huh? It is very easy to nest SWT (or Swing) layuouts in WindowBuilder.

Every container (shell or composite) may have its own layout assigned to it.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby cochand » Thu Jul 07, 2005 12:13 pm

My confusion came in that I was trying to stuff an SWT Layout directly inside another SWT Layout, which I now think I understand to not be possible.

I believe it's accurate to say that it's actually SWT Composites that can be nested. Also, SWT Composites may contain SWT Layouts. Thus you can specify multiple SWT Layouts within one window by using a composite, assigning it a layout, putting additional composites inside that layout, and so on, and so on...
cochand
 
Posts: 17
Joined: Wed Jul 06, 2005 1:20 pm

Postby Eric Clayberg » Sun Jul 10, 2005 2:06 pm

cochand wrote:My confusion came in that I was trying to stuff an SWT Layout directly inside another SWT Layout, which I now think I understand to not be possible.

Layout managers are properties of containers. They don't have children themselves. Nesting of layout managers requires nesting of containers. This is equally true for Swing and SWT.

cochand wrote:I believe it's accurate to say that it's actually SWT Composites that can be nested.

This is also commonly refered to as nesting layouts or nesting layout managers.

cochand wrote:Also, SWT Composites may contain SWT Layouts. Thus you can specify multiple SWT Layouts within one window by using a composite, assigning it a layout, putting additional composites inside that layout, and so on, and so on...

Yes. Swing works the same way with JPanels.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Nested Layouts

Postby Slot Head » Sun Jul 10, 2005 7:07 pm

Hi Jeff. Here is what I would do to get the gui you describe:

1. Start with null layout for your main window.
2. Put two composites in it.
3. Adjuste them so the the left one takes up 1/3 the space like you described.
4. After you get them both just so, chnage the top level layout to FormLayout.
5. Now test it by clicking on the toggle switch thing.
6. Notice that they don't grow with the window.
6. Experiment with the layout out data. I would think you want the left composite to only grow downwards, so try setting its valign to fill. For the right composite, let its halign and valign both balloon out and set them both the fill. Mess around with the other properties like hgrab and vgrab too.
7. Repeatedly use the preview button until you're happy with the results. Be prepared to use undo.
8. If you are used to doing purely visual design, consider using the component tree more. You can drag stuff around in there- it's often easier, for me at least, to get things done in there.
9. Sometimes the designer seems a little stubborn when you are trying to set a width or height near the edge ot the area. Yo may find it easier to simply punch in a number in the properties window.
10 Finally, the up/down/left/right keys on the keyboard seem to me like the best way to nudge a position of something.

HTH
Slot Head
 
Posts: 36
Joined: Sun Jul 10, 2005 9:50 am

Re: Nested Layouts

Postby Eric Clayberg » Sun Jul 10, 2005 7:46 pm

Slot Head wrote:9. Sometimes the designer seems a little stubborn when you are trying to set a width or height near the edge ot the area.

What do you mean? "Stubborn" in what sense? What layout manager are you using?

Are you by chance using FormLayout and running into the margin constraints?

Image

Those can be set to anything you like or even turned off:

Image
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Slot Head » Mon Jul 11, 2005 7:32 am

Thanks for the reply and screenshots, Eric.

Wow, you are really perceptive. Yes, I think the margin constraints may have been causing what I referred to as "stubborn." They're a nice feature; I'll just have to get used to them or change them.
Slot Head
 
Posts: 36
Joined: Sun Jul 10, 2005 9:50 am

Postby Eric Clayberg » Mon Jul 11, 2005 3:07 pm

Slot Head wrote:Wow, you are really perceptive. Yes, I think the margin constraints may have been causing what I referred to as "stubborn." They're a nice feature; I'll just have to get used to them or change them.

The margin constraints were included to make it easy to attach the side of a widget to the side of the window (fairly common in most forms).

Setting the Window Margin to -1 should disable it.

There is also an option to temporarily disable snap points available in the preferences (it defaults to holding the Ctrl key down).
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest