ScrolledComposite Usage

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 Usage

Postby cebarne2 » Mon Jan 19, 2004 12:07 pm

Using 1.2.3beta

I can't seem to get scrolled composite to work correctly.

When I add a scrolled composite, it looks fine. A blank frame with scrollbars. It tells me to add a single compostie or a custom frame. When I click on Composite, then place it in the ScrolledComposite, it places a tiny little composite in the upper-left of the ScrolledComposite. Unusable. If I instruct the ScrolledComposite to expand vertically, horizontally... the Composite then covers the scrollbars.

Can anyone provide a brief step-by-step process to create a working and usable ScrolledComposite with the SWTDesigner?
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby cebarne2 » Mon Jan 19, 2004 12:15 pm

BTW, here are the steps I use that don;'t seem to produce a usable scrolled composite:

1) Add gridlayout
2) Add a TabFolder
-hgrab
-vgrab
-fill both
3) Add a TabItem
4) Add a scrolled Composite
-hgrab
-vgrab
-fill both
5) Add a single Composite to the ScrolledComposite via the control tree

At this point, the Composite from step 5 is a very tiny square in the upper-left corner of the Scrolled Composite.
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Re: ScrolledComposite Usage

Postby Eric Clayberg » Mon Jan 19, 2004 12:37 pm

cebarne2 wrote:Add a single Composite to the ScrolledComposite via the control tree

Rather than dropping the composite on the control tree, drop it on the scrolled composite instead (dropping it on the tree appears to be broken in the beta). Once the composite shows up within the scrolled composite, you can adjust its size as necessary. If you make it larger than its scrolled composite parent, you will see scroll bars. Since the scrollbars are not active, you might want to make the window larger while you lay out the contents of the inner composite, and then shrink it afterwards. Alternatively, you can create the contents of the scrolled composite in a separate class (as a subclass of Composite) and drop an instance of that class in using the Frame tool in the palette.
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

Re: ScrolledComposite Usage

Postby cebarne2 » Mon Jan 19, 2004 1:55 pm

Thank you for your prompt reply. I am always impressed with the turnaround here.

Eric Clayberg wrote:Rather than dropping the composite on the control tree, drop it on the scrolled composite instead (dropping it on the tree appears to be broken in the beta).


This seems to work the exact opposite for me. I can place a ScrolledComposite using the preview window, but I cannot drop a Composite ontop of a ScrolledComposite using the preview window. My cursor turns to the icon with the black slash and circle.

Eric Clayberg wrote:Once the composite shows up within the scrolled composite, you can adjust its size as necessary.


Please elaborate on how to resize the Composite. One I place the Composite within the ScrolledComposite (using the control tree), I get the tiny black frame representing the composite in the Preview Window. If I move my mouse over one of the resize handles, the mouse changes like I should be able to resize it, but dragging the handle does nothing. If I place controls in the tiny Composite, I can barely see the control is in there, but the Composite does not resize to display the entire control.
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Re: ScrolledComposite Usage

Postby Eric Clayberg » Mon Jan 19, 2004 5:24 pm

What version of Eclipse are you using? Are there any exceptions recorded in the Eclipse ".log" file?
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

Re: ScrolledComposite Usage

Postby cebarne2 » Tue Jan 20, 2004 5:53 am

Eric Clayberg wrote:What version of Eclipse are you using? Are there any exceptions recorded in the Eclipse ".log" file?


Version: 2.1.2
Build id: 200311030802

No exceptions in the .log file. Confirmed this by deleting it and recreating the GUI.

At the bottom of this message is some sample code with just a single TabFolder, a TabItem, and a ScrolledComposite.
Using this sample code as a start, my next step would be to place a Composite within the TabFolder. I have just confirmed I MUST place the Composite using the control tree instead of the Preview window. AND, once the Composite is placed (as a tiny black frame in the upper-left of the ScrolledComposite), I cannot figure-out how to resize it (the resize handles do not work).

I tend to use ScrolledComposites frequently as we are often writing front-ends for compilers that have several options; more than can fit on a screen.

Thanks for your help.

Code: Select all
package projectProperties;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.custom.ScrolledComposite;

/**
* @author cebarne2
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class TestPageSWTDesigner extends PropertyPage {

   /* (non-Javadoc)
    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
    */
   protected Control createContents(Composite parent) {
      Composite thisComp = new Composite(parent, SWT.NONE);
      thisComp.setLayout(new GridLayout());
      {
         final TabFolder tabFolder = new TabFolder(thisComp, SWT.NONE);
         tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
         {
            final TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
            {
               final ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
               tabItem.setControl(scrolledComposite);
            }
         }
      }
      return thisComp;
   }

}
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Confirmed with 3.0

Postby cebarne2 » Tue Jan 20, 2004 10:26 am

I confirmed the same behavior in Eclipse 3.0 M6
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Re: Confirmed with 3.0

Postby Eric Clayberg » Tue Jan 20, 2004 9:47 pm

We just posted an updated v1.2.3 beta. Give it a try.
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 cebarne2 » Wed Jan 21, 2004 5:42 am

Thanks for the update.

It now works such that I can put down a Composite and it fills the ScrolledComposite. I can even drag the size of it larger or smaller. I have put controls in it and scrolled successfully. Thank You.

BUT, I can't make it that easy for you!

The project I will be working on, for a compiler front-end, will be dynamically creating controls inside the ScrolledComposite. I intend to use the Scrolled composite as an interface to compiler options, the number of which could change dramatically between compiler versions. That means, I cannot hard-code the size of the child Composite within the ScrolledComposite. So, instead, I will be using the following commands after the controls are placed:

Code: Select all
composite.setsize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
scrolledComposite.setContent(composite);


I know SWT-Designer will never do what I want since the SWT-Designer cannot follow my own methods to get the dynamically created controls, and then place them in the Preview... but I would suggest you enable support for "computeSize" so the child composite can shrink and grow as new controls are added to it from the Designer. This can be an option in the Designer window (not necessarily a default option).

I dislike hard-coded sizes especially in a platform independant GUI. That is why I like ScrolledComposite so much. I do not have to worry about the target platform's resolution.

Thanks for all the great work!
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby Eric Clayberg » Fri Jan 23, 2004 12:19 pm

cebarne2 wrote:The project I will be working on, for a compiler front-end, will be dynamically creating controls inside the ScrolledComposite. I intend to use the Scrolled composite as an interface to compiler options, the number of which could change dramatically between compiler versions. That means, I cannot hard-code the size of the child Composite within the ScrolledComposite. So, instead, I will be using the following commands after the controls are placed:
Code: Select all
composite.setsize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
scrolledComposite.setContent(composite);

I know SWT-Designer will never do what I want since the SWT-Designer cannot follow my own methods to get the dynamically created controls, and then place them in the Preview... but I would suggest you enable support for "computeSize" so the child composite can shrink and grow as new controls are added to it from the Designer. This can be an option in the Designer window (not necessarily a default option).


Give this a try:

Code: Select all
public class ScrolledCompositeTest {

   private Composite composite;
   public static void main(String[] args) {
      ScrolledCompositeTest window = new ScrolledCompositeTest();
      window.open();
   }
   public void open() {
      final Display display = new Display();
      final Shell shell = new Shell();
      shell.setSize(400, 300);
      shell.setLayout(new FillLayout());
      shell.setText("ScrolledComposite Test");
      {
         final ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
         {
            composite = new Composite(scrolledComposite, SWT.NONE);
            composite.setBounds(0, 0, 300, 200);
            composite.setBackground(ResourceManager.getColor(SWT.COLOR_CYAN));
            scrolledComposite.setContent(composite);
            {
               final Button button = new Button(composite, SWT.NONE);
               button.setBounds(150, 115, 60, 35);
               button.setText("button");
            }
         }
      }
      composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
      shell.open();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
   }
}

If you make the composite a field, you can then add the composite.setSize(...) call at the end, and the Designer will leave it alone.
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 cebarne2 » Fri Jan 23, 2004 12:37 pm

Eric,

Thanks for posting that technique. I will definitely use it.

The more specific request was to provide an option in the Designer to make child composites of ScrolledComposites more dynamic. That is:

-An option to make the child composite fill the ScrolledComposite
-An option to make the child composite grow (down) as more controls are added than it can currently hold.

This would be categorized as a user-interface enhancement since a knowledgable programmer can do this in code after the controls are added.

Let me know if I need to explain this any better (and I will try).

Thanks,
Chad
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest