ScrolledComposite and Composite child resize issue

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

ScrolledComposite and Composite child resize issue

Postby atlacatl » Sat Dec 29, 2007 6:17 pm

I add a Composite with a grid layout to a ScrolledComposite.

The scrolling works (horizontal and vertical), but I want the Composite child to be the same size of the ScrolledComposite--as if I'm using a fill layout.

Is there a way to get the child composite to be the same size as the ScrolledComposite?

The relevant code looks like:

Code: Select all
final ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

final Composite composite = new Composite(scrolledComposite, SWT.NONE);
composite.setLocation(0, 0);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
composite.setLayout(gridLayout);

...

composite.setSize(499, 236);
scrolledComposite.setContent(composite);

I want the setSize to maximize to the scrolledComposite size...

Any help would be great. Thanks.
Last edited by atlacatl on Sun Dec 30, 2007 8:29 am, edited 1 time in total.
atlacatl
 
Posts: 6
Joined: Fri Mar 30, 2007 12:58 pm

Postby atlacatl » Sat Dec 29, 2007 9:24 pm

I should mention that I am using SWT Designer Pro. v6.5.0 with Eclipse 3.3.
atlacatl
 
Posts: 6
Joined: Fri Mar 30, 2007 12:58 pm

Postby Eric Clayberg » Wed Jan 02, 2008 11:19 am

Why not setSize() on the Composite using getSize() from the ScrolledComposite?

Since you probably can't get the size from the ScrolledComposite until after the window has opened, you would want to set the size of the Composite sometime after that (maybe in response to the controlResized event of the ScrolledComposite itself).

I should also point out that general SWT questions are better directed to the Eclipse SWT newsgroup.
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 atlacatl » Wed Jan 02, 2008 11:37 am

Eric Clayberg wrote:I should also point out that general SWT questions are better directed to the Eclipse SWT newsgroup.


I get that. However, I figured since I'm a paying customer, I could get some help from the Instantiations team. ;)

As per my problem, I found a solution. I'm using:
Code: Select all
...
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
...

The problem I'm having is that if these two flags are set, the scroll bars (horizontal or vertical) never show up, regardless of how small the scrolled container gets.

Perhaps it was my lack of understanding of the scrolled container, but I wanted to still expand horizontal and vertical and still observe my minimum size requirements (the child container's size).

So for my needs, I only set the crolledComposite.setExpandHorizontal(true). So this way I can resize my main window and displays the vertical scroll bar only.

Anyway, for now what I have will do. And thanks for your reply.
atlacatl
 
Posts: 6
Joined: Fri Mar 30, 2007 12:58 pm

Postby Eric Clayberg » Wed Jan 02, 2008 12:45 pm

Without a real example, I have a hard time envisioning why you would want the inner composite to be the same size as its scrolled parent and still want to see scrollbars. If the two are the same size, there is nothing to scroll.
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 atlacatl » Wed Jan 02, 2008 1:27 pm

Eric Clayberg wrote:Without a real example, I have a hard time envisioning why you would want the inner composite to be the same size as its scrolled parent and still want to see scrollbars. If the two are the same size, there is nothing to scroll.


It is hard without looking at it. This is the issue, in images:

I have a view with a couple of SWT components (buttons, etc., as part of a composite). I want the composite to have a minimum size. Without the flags I mentioned above, the scrollbars display properly if the scrolled composite gets smaller than the actual composite size. As in:

Image

However, when the main window (or view) is big enough, I want the child composite to fill the scrolled composite. As in:

Image

Do you see my problem? The composite has a size set; however, I want the composite to be flushed with the scrolled composite's border.

Now, if I set the expand flags to true, and I make the window smaller than the actual size of the composite, the scrollbars never display--and I was expecting them to show up. As in:

Image

However, when expanded, the child composite is flushed with the scrolled composite. As in:

Image

What I have right now kind of works (I only set to expand horizontally), but I have the same problem with the vertical spacing. As in:

Image

Again, I can live with what I have. But I think I'm misunderstanding how the ScrolledComposite works, as I don't think I'm the only one with this requirement: "flush a composite to the edge of the scrolled composite, and still respect the minimum size of the child composite so that scrollbars display if they are in fact needed."

Thanks for any possible solution, Eric. And in the future I will use the Eclipse SWT forums for this type of question.
atlacatl
 
Posts: 6
Joined: Fri Mar 30, 2007 12:58 pm

Postby Eric Clayberg » Wed Jan 02, 2008 2:02 pm

What you are describing is fairly dynamic behavior that SWT does not support by default.

You should be able to achieve that affect by dynamically setting the Composite's size based on the ScrolledComposite's size any time the ScrolledComposite changes size.
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 atlacatl » Wed Jan 02, 2008 8:50 pm

Eric Clayberg wrote:What you are describing is fairly dynamic behavior that SWT does not support by default.

You should be able to achieve that affect by dynamically setting the Composite's size based on the ScrolledComposite's size any time the ScrolledComposite changes size.


:)

Hence, the original question. I know I can code it, I just thought someone had done before. Or SWT could do by default. Thanks.
atlacatl
 
Posts: 6
Joined: Fri Mar 30, 2007 12:58 pm

Postby Eric Clayberg » Thu Jan 03, 2008 6:49 am

Looking at your screen shots again, maybe I am misunderstanding what you are trying to do.

Have you tried setting setExpandHorizontal() to true and setMinWidth() to some value?
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 atlacatl » Thu Jan 03, 2008 7:13 am

Eric Clayberg wrote:...Have you tried setting setExpandHorizontal() to true and setMinWidth() to some value?


I had not. I just did, and that worked! I used setMinSize()...

That's exactly what I was missing, and exactly the behavior I was expecting. I was setting the min height to the composite and not the scrolled composite. I think it's a Swing thing...

Thanks!

BTW, your book "Eclipse: Building Commercial-Quality Plug-ins (2nd Ed)" is very good. I use it often.
atlacatl
 
Posts: 6
Joined: Fri Mar 30, 2007 12:58 pm

Postby Eric Clayberg » Thu Jan 03, 2008 7:30 pm

atlacatl wrote:your book "Eclipse: Building Commercial-Quality Plug-ins (2nd Ed)" is very good. I use it often.

Thanks! Look for the 3rd edition later this year. :-)
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 2 guests