[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Re: Dialog having a Scrollbar?

I worked for a few hours on this one, as well.....

I actually, build up my widgets in the scrolled area dynamically after the dialog has been built and it works well.

Here's the first part. I like Groups surrounding my widgets as it appears to make things easier to teach users, plus I can delegate widget creation to other classes and reuse them in other areas.

	public void createControl(Composite parent) {
		composite = new Composite(parent, SWT.NONE);

		composite.setLayout(new GridLayout(1, false));
		setControl(composite);

        //	Add file group.
        //	list of files in the directory.

		exerciseFileGroup = new Group (composite, SWT.NONE);
		exerciseFileGroup.setText("Exercises");

		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		gridData.widthHint = widthHint;
		gridData.heightHint = heightHint;
		exerciseFileGroup.setLayoutData(gridData);
		exerciseFileGroup.setLayout(new GridLayout (1,false));
		
		//	Now for the list of files

	        scrolledComposite = new ScrolledComposite (exerciseFileGroup,
        		SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

        	GridData scGridData = new GridData();
	        scGridData.grabExcessHorizontalSpace = true;
        	scGridData.grabExcessVerticalSpace = true;
	        scGridData.horizontalAlignment = SWT.FILL;
	        scGridData.verticalAlignment = SWT.FILL;
	        scrolledComposite.setLayoutData(scGridData);

innerComposite = new Composite (scrolledComposite, SWT.NONE);
scrolledComposite.setContent(innerComposite);
innerComposite.setLayoutData(new GridData (SWT.FILL, SWT.FILL, true, false));
innerComposite.setLayout(new GridLayout (3, false));


	        addSomeWidgetsHere (innerComposite);

innerComposite.setSize (innerComposite.computeSize (SWT.DEFAULT, SWT.DEFAULT));

	        scrolledComposite.setVisible(false);
	}

Then, in some other method, I dynamically add some widgets (in a loop):

	public addWidgetsDynamically (Composite	innerComposite)
	{
		for () {
			this.fileLabel = new Label(innerComposite), SWT.NONE);
			this.fileLabel.setText(fileName);
			this.fileLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
				false, false));
		
			this.text = new Text(innerComposite), SWT.BORDER);
			this.text.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
				true, false));
		}

		//	Need to recalculate the size of the parent widgets to display
		//	this new list of files.
					
	        scrolledComposite.setVisible(true);

		Point size = innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
		size.y += exerciseList.size() * 2;
		innerComposite.setSize(size);
		exerciseFileGroup.layout();
	}
		
Hope this helps.

abhi wrote:
Hi,

A very basic question. How can one have a Dialog with a scrollbar?
I have a class extending TitleAreaDialog. This dialog will contain a lot of widgets (checkboxes) that make it necessary to have a vertical scrollbar. I have tried:


In the constructor of the dialog:
setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL | SWT.H_SCROLL | SWT.V_SCROLL);


In createDialogArea(Composite parent):
ScrolledForm scrolledForm = new ScrolledForm(parent, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledForm.setExpandVertical(true);
scrolledForm.setExpandHorizontal(true);
scrolledForm.setMinSize(0, 0); // also tried scrolledForm.setMinSize(parent.getSize());


Nothing works, no scroll bars are seen even though there are more widgets than are visible.

Any pointers (especially code snippets) are highly appreciated.

TIA,
Best Regards,
-abhi