Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ScrolledComposite in JFace(Scrollbar appears only when I resize the window)
ScrolledComposite in JFace [message #896724] Thu, 19 July 2012 09:51 Go to next message
sanchayita sarkar is currently offline sanchayita sarkar
Messages: 5
Registered: July 2012
Junior Member
Hi

I am newbie in this jface area. I have created a jface wizard and have implemented the scrollbar functionality in it. However, I am facing one problem. In one of my wizard page, I have the logic that based on the selection of this page, the user will have different page when they click on the next page.

For eg, lets say there are two radio buttons 1 and 2.

1 --> Next --> Next1
2 --> Next --> Next2

If the user selects 1 and clicks Next button in the wizard, the user will go to Next1 page, whereas, if the user selects 2 and clicks Next button in the wizard, the user will go to Next2 page.

I have implemented the scrollbar functionality for all the pages. Now when I select 1 and click Next button, I can see the scrollbar and view the content of the next page completely with the help of the scrollbar. But when I select 2 and click the Next button, the contents in the Next2 page appears clipped with no scrollbar. I can only view a part of the page. However, as soon as I resize the page a little bit, the scrollbar appears.

Here is the code snippet for the scrollbar which I used for all the pages.

sc = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
containerMain = new Composite(sc, SWT.NULL);
sc.setContent(containerMain);
GridLayout layout = new GridLayout();
layout.numColumns = ncol;
containerMain.setLayout(layout);
containerMain.setSize(containerMain.computeSize(SWT.DEFAULT,
SWT.DEFAULT));


I want only vertical scrollbar, so I have not included H_SCROLL while creating the scrolledcomposite.

Can anyone please put some light on where I am missing something? I need it on an urgent basis, so it would really be great of you if anyone can response with some ideas. Thanks a lot in advance.
Re: ScrolledComposite in JFace [message #896731 is a reply to message #896724] Thu, 19 July 2012 10:11 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 402
Registered: December 2009
Location: Prague
Senior Member
Hi,

it's hard to say without better overview of your code. I would try the second way of using the ScrolledComposite as mentioned in it's javadoc

sc = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
containerMain = new Composite(sc, SWT.NULL);
sc.setContent(containerMain);
GridLayout layout = new GridLayout();
layout.numColumns = ncol;
containerMain.setLayout(layout);
sc.setminSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));

[Updated on: Thu, 19 July 2012 10:12]

Report message to a moderator

Re: ScrolledComposite in JFace [message #896735 is a reply to message #896731] Thu, 19 July 2012 10:20 Go to previous messageGo to next message
sanchayita sarkar is currently offline sanchayita sarkar
Messages: 5
Registered: July 2012
Junior Member
Thanks a lot Jan.. I think I should have mentioned in my previous message itself.. Actually I have tried with both ways of creating the scrollbar, the way which I have mentioned in my previous original msg as well as the one which you have mentioned from the JavaDoc.. But neither of them are working for me.. If I use one way of creating the scrollbar(lets say the way which I created by setting the size of the composite) for a JFace wizard, then do I need to use that way for all the pages in the wizard, or I can also use both the ways for different pages?

Thanks in advance.
Re: ScrolledComposite in JFace [message #896744 is a reply to message #896735] Thu, 19 July 2012 10:50 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 402
Registered: December 2009
Location: Prague
Senior Member
Do you create the scrolled composite inside the every wizard page approximately as follows?
public class MyWizardPage extends WizardPage {

    public MyWizardPage() {
        super("My Wizard");
    }

    public void createControl(Composite parent) {
        ScrolledCompositesc = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        Composite containerMain = new Composite(sc, SWT.NULL);
        sc.setContent(containerMain);
        GridLayout layout = new GridLayout();
        layout.numColumns = ncol;
        containerMain.setLayout(layout);
        sc.setminSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));

        // Important!
        setControl(composite);
    }
}
Re: ScrolledComposite in JFace [message #896888 is a reply to message #896744] Fri, 20 July 2012 06:03 Go to previous messageGo to next message
sanchayita sarkar is currently offline sanchayita sarkar
Messages: 5
Registered: July 2012
Junior Member
Thanks for the response.. Yes exactly.. I do this for every wizard page in the createControl method.. But, the code which you suggested, I mean

ScrolledCompositesc = new ScrolledComposite(parent, SWT.BORDER | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
Composite containerMain = new Composite(sc, SWT.NULL);
sc.setContent(containerMain);
GridLayout layout = new GridLayout();
layout.numColumns = ncol;
containerMain.setLayout(layout);
sc.setminSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));

If I use the above code, the scrollbar does not appear at all, I can see the clipped view of the content in a page. Whereas if I use the below code,

ScrolledComposite sc = new ScrolledComposite(parent, SWT.BORDER
| SWT.V_SCROLL);
container = new Composite(sc, SWT.NULL);
sc.setContent(container);
GridLayout layout = new GridLayout();
layout.numColumns = ncol;
container.setLayout(layout);
container.setSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));

I can very well see the scrollbar. But the issue which I have mentioned in my original message (where scrollbar appears only when I resize the page for a particular wizard page) is still there..

Another thing is, as you said in your code snippet about the setControl thing.. When I pass composite to the setControl, I mean when I call

setControl(composite)

as you asked to, I see only blank pages in the wizard, the contents of the page are no more visible. Only when I call

setControl(sc)

where sc is the ScrolledComposite, the contents are visible. Is this some kind of issue or I am missing something?

Thanks a lot in advance..
Re: ScrolledComposite in JFace [message #897082 is a reply to message #896888] Sat, 21 July 2012 09:46 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 402
Registered: December 2009
Location: Prague
Senior Member
Well, the WizardDialog try to set its bounds to be able to hold the biggest wizardPage it contains.

Look at the code bellow, it works for me that way
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;

public class AAA {

	public static void main(String[] args) {
		Display display = new Display();
		Wizard wizard = new Wizard() {
			
			public boolean performFinish() {
				return false;
			}

			public void addPages() {
				addPage(new WizardPage("aaa") {
					
					public void createControl(Composite parent) {
						final Composite rootComposite = new Composite(parent, SWT.NONE);
						rootComposite.setLayout(GridLayoutFactory.fillDefaults().create());
						
						final ScrolledComposite sc = new ScrolledComposite(rootComposite, SWT.BORDER | SWT.V_SCROLL);
						sc.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
						sc.setExpandHorizontal(true);
						sc.setExpandVertical(true);
						
						final Composite containerMain = new Composite(sc, SWT.NULL);
						containerMain.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());
						
						for (int i = 0; i < 50; i++) {
							final Label label = new Label(containerMain, SWT.NONE);
							label.setText("Label " + i + 1);
						}
						
						sc.setContent(containerMain);
						sc.setMinSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));
						
						setControl(rootComposite);
					}
				});
			}
			
		};
		new WizardDialog(null, wizard).open();
		display.dispose();
	}

}

As you can see I had to create an extra "root" Composite with the GridLayout and set the vertical hint of the ScrolledComposite's Grid data to 200 (just a reasonable value).
When the dialog computes size of the page, it asks the control you create in the createControl method (it's the rootComposite) for its size. And that size is computed by its layout.
If you don't specify the hint (try to delete ".hint(SWT.DEFAULT, 200)"), the height of the scrolled composite is such that it can be able show all Labels inside, so the dialog gets taller and you can't see the scrollbar until you resize the dialog to be smaller.
Re: ScrolledComposite in JFace [message #897752 is a reply to message #897082] Wed, 25 July 2012 04:21 Go to previous messageGo to next message
sanchayita sarkar is currently offline sanchayita sarkar
Messages: 5
Registered: July 2012
Junior Member
Hey Jan

Thank you very much for the code.. It is perfectly working now.. I think it was because of me not creating this rootComposite and passing sc to the setControl.. However, I just had to remove 2 lines from your code to bring this scrollbar.. With the below 2 lines the scrollbar was somehow not appearing..

sc.setExpandHorizontal(true);
sc.setExpandVertical(true);

As soon as I commented out the above 2 lines the scrollbar was working fine..

Anyways, thanks a lot for all the help and your time..

Sanchayita..
Re: ScrolledComposite in JFace [message #898300 is a reply to message #897082] Thu, 26 July 2012 03:12 Go to previous messageGo to next message
sanchayita sarkar is currently offline sanchayita sarkar
Messages: 5
Registered: July 2012
Junior Member
Hi Jan

The code which you have given as an example in your previous reply, that code is working fine for me for the 2nd page, but with the same code, I am having the same problem in the 3rd page. As soon as I reach the 3rd page, I see the clipped content of that page and I can only see the scroll bar when I resize the page. So basically the code which you provided has solved the issue for one page but it didnt solve it for the next page. Sad

Do you have any idea why is it so? I shall really be grateful if you can provide with some hints. Thanks a lot.

Sanchayita.
Re: ScrolledComposite in JFace [message #898304 is a reply to message #898300] Thu, 26 July 2012 03:27 Go to previous message
Jan Krakora is currently offline Jan Krakora
Messages: 402
Registered: December 2009
Location: Prague
Senior Member
I have tried that and it works
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

public class AAA {

	public static void main(String[] args) {
		Display display = new Display();
		Wizard wizard = new Wizard() {

			@Override
			public boolean performFinish() {
				return false;
			}

			@Override
			public void addPages() {
				addPage(new WizardPage("aaa") {

					@Override
					public void createControl(Composite parent) {
						final Composite rootComposite = new Composite(parent, SWT.NONE);
						rootComposite.setLayout(GridLayoutFactory.fillDefaults().create());

						final ScrolledComposite sc = new ScrolledComposite(rootComposite, SWT.BORDER | SWT.V_SCROLL);
						sc.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
						sc.setExpandHorizontal(true);
						sc.setExpandVertical(true);

						final Composite containerMain = new Composite(sc, SWT.NULL);
						containerMain.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());

						for (int i = 0; i < 50; i++) {
							final Label label = new Label(containerMain, SWT.NONE);
							label.setText("Label " + i + 1);
						}

						sc.setContent(containerMain);
						sc.setMinSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));

						setControl(rootComposite);
					}
				});
				addPage(new WizardPage("bbb") {

					@Override
					public void createControl(Composite parent) {
						final Composite rootComposite = new Composite(parent, SWT.NONE);
						rootComposite.setLayout(GridLayoutFactory.fillDefaults().create());

						final ScrolledComposite sc = new ScrolledComposite(rootComposite, SWT.BORDER | SWT.V_SCROLL);
						sc.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
						sc.setExpandHorizontal(true);
						sc.setExpandVertical(true);

						final Composite containerMain = new Composite(sc, SWT.NULL);
						containerMain.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());

						for (int i = 0; i < 50; i++) {
							final Label label = new Label(containerMain, SWT.NONE);
							label.setText("Label " + i + 1);
						}

						sc.setContent(containerMain);
						sc.setMinSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));

						setControl(rootComposite);
					}
				});
				addPage(new WizardPage("ccc") {

					@Override
					public void createControl(Composite parent) {
						final Composite rootComposite = new Composite(parent, SWT.NONE);
						rootComposite.setLayout(GridLayoutFactory.fillDefaults().create());

						final ScrolledComposite sc = new ScrolledComposite(rootComposite, SWT.BORDER | SWT.V_SCROLL);
						sc.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
						sc.setExpandHorizontal(true);
						sc.setExpandVertical(true);

						final Composite containerMain = new Composite(sc, SWT.NULL);
						containerMain.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());

						for (int i = 0; i < 50; i++) {
							final Label label = new Label(containerMain, SWT.NONE);
							label.setText("Label " + i + 1);
						}

						sc.setContent(containerMain);
						sc.setMinSize(containerMain.computeSize(SWT.DEFAULT, SWT.DEFAULT));

						setControl(rootComposite);
					}
				});
			}

		};
		new WizardDialog(null, wizard).open();
		display.dispose();
	}

}
Previous Topic:Getting IValueProperty of a certain value in a MAP
Next Topic:Deferred content provider
Goto Forum:
  


Current Time: Wed May 22 10:54:49 EDT 2013

Powered by FUDForum. Page generated in 0.02052 seconds