Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Making Composite to ScrolledComposite
Making Composite to ScrolledComposite [message #905536] Thu, 30 August 2012 15:27 Go to next message
Johann Vogel is currently offline Johann VogelFriend
Messages: 20
Registered: February 2012
Junior Member
I have to patch an eclipse-swt-application. To be concrete I simply have to wrap a composite inside of an editor (EditorPart) with a scrollbar. The first try was to set the V_-Scroll layout-argument, what gives me scrollbars that don't work, but then i tried to simply replace the Composite with ScrolledComposite (keeping V_scroll), and the whole content disappered (same as using composite with setVisible(false) ). The layout of the containing element is a grid-layout, if this is relevant.

What do I have to change, that my content will be visible again?

Sorry if I didn't provide information, I am quite new to SWT.
Re: Making Composite to ScrolledComposite [message #905567 is a reply to message #905536] Thu, 30 August 2012 16:42 Go to previous messageGo to next message
Sharon Snyder is currently offline Sharon SnyderFriend
Messages: 56
Registered: September 2010
Member

Hi Johann,

You have to set the content in the ScrolledComposite.

If you switch back to your composite....and then wrap that with a ScrolledCOmposite. Don't forget to call scrolledComposite.setContent(yourOriginalComposite)!

The javadoc contains a simple example. I would advise you to take a look at it.

In general there are plenty of code snippets, and javadocs available to help you - they are very complete.

Sharon
Re: Making Composite to ScrolledComposite [message #905947 is a reply to message #905567] Fri, 31 August 2012 11:01 Go to previous messageGo to next message
Johann Vogel is currently offline Johann VogelFriend
Messages: 20
Registered: February 2012
Junior Member
Thank you Sharon

I have already read that, but just to method 1, which didn't work for me. I also tried method 2, but my fault was that I used scrollComp.setMinSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT)); before comp was "filled" and had the real size.

So, my solution was changing:
public void createPartControl(Composite parent) {
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
top.setFont(new Font(Display.getDefault(), "Tahoma", 10, SWT.NORMAL));
...
createHead(); //fill top

to
ScrolledComposite toptop = new ScrolledComposite(parent, SWT.H_SCROLL|SWT.BORDER); //this adds left-to-right scrolling, what is quite confusing, because i'd expect H_Scroll to add a scrollbar that scrolls horicontally
toptop.setExpandVertical(true);
toptop.setExpandHorizontal(true); //important: both, otherwise it didn't even get visible for me. even if i just h_Scroll

top = new Composite(toptop, SWT.NONE);
top.setLayout(new GridLayout());
top.setFont(new Font(Display.getDefault(), "Tahoma", 10, SWT.NORMAL));
toptop.setContent(top); //also important! otherwise empty
..
createHead(); //fill top
toptop.setMinSize(top.computeSize(SWT.DEFAULT, SWT.DEFAULT)); //make this AFTER fillig the Composite, otherwise it won't work!
Re: Making Composite to ScrolledComposite [message #905984 is a reply to message #905947] Fri, 31 August 2012 12:16 Go to previous message
Sharon Snyder is currently offline Sharon SnyderFriend
Messages: 56
Registered: September 2010
Member

Yes, that is correct, you need to set minSize after it's been filled. I'm glad you figured it out and posted your solution.

Posting the code helps to understand just what your problem is. I know when I first used the ScrolledComposite I kept forgetting to setContent(), so I naturally assumed that was where you were having your problems. Smile
Previous Topic:java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jface.text.TextSelection
Next Topic:Image getting shrinked/expanded
Goto Forum:
  


Current Time: Sat Apr 20 02:48:45 GMT 2024

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

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

Back to the top