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  |
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   |
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 #896888 is a reply to message #896744] |
Fri, 20 July 2012 06:03   |
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   |
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 #898304 is a reply to message #898300] |
Thu, 26 July 2012 03:27  |
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();
}
}
|
|
|
Goto Forum:
Current Time: Wed May 22 10:54:49 EDT 2013
Powered by FUDForum. Page generated in 0.02052 seconds
|