Does ScrolledComposite work in Dialog? [message #114790] |
Mon, 08 December 2008 09:07  |
Eclipse User |
|
|
|
Hello,
I would like a scrolling popup dialog. I have subclassed this class
org.eclipse.jface.dialogs.Dialog. My dialogs work, but nothing I try
makes them scrolling. I have successfully gotten WizardPages to scrol
using ScrolledComposite. Here is a code snippet, which creates a
ScrolledComposite, which contains "pageComposite", which contains a text
at the top, plus "formComposite". "formComposite" contains 150 form
elements.
What I see is the top of the form, but no scroll bars, and no "Save" or
"Cancel" buttons at the bottom.
Thanks!
David
@Override
protected Control createDialogArea(Composite parent) {
Shell shell = parent.getShell();
shell.setText(getTitle());
scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL |
SWT.H_SCROLL | SWT.RESIZE);
GridLayout gl = new GridLayout(1, true);
scrolledComposite.setLayout(gl);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
GridData.GRAB_HORIZONTAL);
scrolledComposite.setLayoutData(gridData);
pageComposite = new Composite(scrolledComposite, SWT.NONE);
gl = new GridLayout(1, true);
pageComposite.setLayout(gl);
gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
pageComposite.setLayoutData(gridData);
messageText = new Text(pageComposite, SWT.WRAP | SWT.READ_ONLY);
messageText.setText(getMessage());
gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
GridData.GRAB_HORIZONTAL);
messageText.setLayoutData(gridData);
formComposite = new Composite(pageComposite, SWT.NONE);
scrolledComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
scrolledComposite.setMinSize(pageComposite.computeSize(SWT.D EFAULT,
SWT.DEFAULT));
}
});
//add 150 form elements to the formComposite:
addFormElements();
scrolledComposite.setContent(pageComposite);
scrolledComposite.setMinSize(pageComposite.computeSize(SWT.D EFAULT,
SWT.DEFAULT));
return scrolledComposite;
}
|
|
|
Re: Does ScrolledComposite work in Dialog? [message #114985 is a reply to message #114790] |
Tue, 09 December 2008 08:08  |
Eclipse User |
|
|
|
I found the solution for my problem with scroll bars not showing up/absent
from my Dialog. Here was the helpful post I found
http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/m sg27482.html
The fix for me was to change setMinSize() of the ScrolledComposite to the
size of itself, like this
scrolledComposite.setMinSize(scrolledComposite.computeSize(S WT.DEFAULT,
SWT.DEFAULT));
Below is my code that works
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(new GridLayout());
Shell shell = parent.getShell();
shell.setText(getTitle());
ScrolledComposite scrolled = new ScrolledComposite(container,
SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
scrolled.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrolled.setLayout(new GridLayout());
scrolled.setExpandVertical(true);
scrolled.setExpandHorizontal(true);
scrolledComposite = new ScrolledComposite(container, SWT.V_SCROLL |
SWT.H_SCROLL);
GridLayout gl = new GridLayout();
scrolledComposite.setLayout(gl);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
GridData gridData = new GridData(GridData.FILL_BOTH);
scrolledComposite.setLayoutData(gridData);
pageComposite = new Composite(scrolledComposite, SWT.NONE);
gl = new GridLayout(1, true);
pageComposite.setLayout(gl);
gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
pageComposite.setLayoutData(gridData);
messageText = new Text(pageComposite, SWT.WRAP | SWT.READ_ONLY);
if (getMessage() != null) {
messageText.setText(getMessage());
}
gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
GridData.GRAB_HORIZONTAL);
messageText.setLayoutData(gridData);
formComposite = new Composite(pageComposite, SWT.NONE);
scrolledComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
scrolledComposite.setMinSize(scrolledComposite.computeSize(S WT.DEFAULT,
SWT.DEFAULT));
}
});
addFormElements();
scrolledComposite.setContent(pageComposite);
scrolledComposite.setMinSize(scrolledComposite.computeSize(S WT.DEFAULT,
SWT.DEFAULT));
return scrolledComposite;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03560 seconds