Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ScrolledComposite in TitleAreaDialog
ScrolledComposite in TitleAreaDialog [message #1232177] Thu, 16 January 2014 11:11 Go to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 128
Registered: March 2012
Location: Italy
Senior Member

Goodmorning everyone,

I've got a TitleAreaDialog with many controls and I'm trying to add a ScrolledComposite to scroll them.

I've seen some examples and snippets and this is what I've done:
public class TestDialog extends TitleAreaDialog {

	public TestDialog(Shell parentShell) {
		super(parentShell);
		
	}
	
	@Override
    protected Control createDialogArea(Composite parent) {
		Composite superParent = (Composite) super.createDialogArea(parent);
		final ScrolledComposite scrollComposite = new ScrolledComposite(superParent, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL);
		scrollComposite.setAlwaysShowScrollBars(true);
		final Composite container = new Composite(scrollComposite, SWT.NONE);
		GridLayout layout=new GridLayout();
        layout.numColumns=1;
		container.setLayout(layout);

		for(int i = 0; i <= 50; i++) {
			Label label = new Label(container, SWT.NONE);
			label.setLayoutData(new GridData());
			if (i % 3 == 0) label.setImage(ImageUtils.ICON_ENTE_COLLETTIVO);
			if (i % 3 == 1) label.setImage(ImageUtils.ICON_NUOVA_PRATICA);
			if (i % 3 == 2) label.setImage(ImageUtils.ICON_PERSONE);
		}
		
		
		scrollComposite.setContent(container);
		scrollComposite.setExpandVertical(true);
		scrollComposite.setExpandHorizontal(true);
		scrollComposite.addControlListener(new ControlAdapter() {
			@Override
			public void controlResized(ControlEvent e) {
				Rectangle r = scrollComposite.getClientArea();
				scrollComposite.setMinSize(container.computeSize(r.width, r.height));
			}
		});
		
		
		return scrollComposite;
	}
	
	@Override
	protected Point getInitialSize() {
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
		return new Point(screenWidth/2, screenHeight);
	}

}


But the result is unsatisfactory:
http://s22.postimg.org/haakjyctt/Dialog.png

As you can see, scrollbar is disabled and oversize. Can someone help me?

Very thank you.
Re: ScrolledComposite in TitleAreaDialog [message #1244276 is a reply to message #1232177] Wed, 12 February 2014 05:28 Go to previous message
Ali Malik is currently offline Ali MalikFriend
Messages: 27
Registered: August 2013
Junior Member
Hi,

It seems you didn't set any layout for the scroll composite, that's why you couldn't get to see the end of the vertical scroll bar, or the horizontal scroll bar.
Also, when I did set the layout, the scroll bars appeared in disabled mode. Turned out, you were re-sizing it incorrectly.
Find the correct code, working as you want, below.

public class TestDialog extends TitleAreaDialog {

	public TestDialog(Shell parentShell) {
		super(parentShell);
		
	}
	
	@Override
    protected Control createDialogArea(Composite parent) {
		parent.setLayout(new GridLayout());
		Composite superParent = (Composite) super.createDialogArea(parent);
		final ScrolledComposite scrollComposite = new ScrolledComposite(superParent, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL);
		scrollComposite.setAlwaysShowScrollBars(true);
		scrollComposite.setLayoutData(new GridData(SWT.NONE, SWT.NONE, true, true));
		scrollComposite.setLayout(new GridLayout());
		final Composite container = new Composite(scrollComposite, SWT.NONE);
		GridLayout layout=new GridLayout();
        layout.numColumns=1;
		container.setLayout(layout);

		for(int i = 0; i <= 50; i++) {
			Label label = new Label(container, SWT.NONE);
			label.setLayoutData(new GridData());
			if (i % 3 == 0) label.setImage(ImageUtils.ICON_ENTE_COLLETTIVO);
			if (i % 3 == 1) label.setImage(ImageUtils.ICON_NUOVA_PRATICA);
			if (i % 3 == 2) label.setImage(ImageUtils.ICON_PERSONE);
		}
		
		
		scrollComposite.setContent(container);
		scrollComposite.setExpandVertical(true);
		scrollComposite.setExpandHorizontal(true);
		scrollComposite.addControlListener(new ControlAdapter() {
			@Override
			public void controlResized(ControlEvent e) {
				scrollComposite.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
			}
		});
		
		
		return scrollComposite;
	}
	
	@Override
	protected Point getInitialSize() {
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
		return new Point(screenWidth/2, screenHeight);
	}

}
Previous Topic:Source Provider State ignored by Handler
Next Topic:Solid tutorial for creating Eclipse RCP product
Goto Forum:
  


Current Time: Sun Dec 21 08:32:13 GMT 2014

Powered by FUDForum. Page generated in 0.02485 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software