Search code examples
javaswtzest

Remove scrollbar from inner composite but retain scrollbar of the outer composite


I am using a composite with fillLayout as inner composite and ScrollComposite as outer composite .

I have fixed the size of outer composite. When I have scrollbar in outer composite but no scroll bar in inner composite then I am getting complete information when I export the composite data as png. But issue arises when information being displayed is too large as a result there is scrollbar for inner composite also.

This is just a snippet of what is done:

FillLayout layout = new FillLayout(SWT.HORIZONTAL);

final ScrolledComposite scrolledComposite = new ScrolledComposite(getContainer(), SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);

final Composite composite = new Composite(scrolledComposite, SWT.NONE);     
composite.setLayout(layout);

GraphViewer gvTree = new GraphViewer(composite, SWT.NONE);

<Code to populate data in the tree>

gvTree.setLayoutAlgorithm(treeLayout,true); 

scrolledComposite.setContent(composite);
scrolledComposite.setMinSize(1000,composite.getBounds().height);

Solution

  • I found that in order to avoid scrollbar in the inner composite when outer composite is ScrolledComposite we need to ensure that the minSize of the ScrolledComposite is always greater than the inner composite size.

    In order to ensure that ScrolledComposite size is correct I changed

     scrolledComposite.setMinSize(1000,composite.getBounds().height);
    **to** 
    scrolledComposite.setMinSize(gvTree.getNodeElements().length*160,
    composite.getBounds().height);
    

    This ensure that after graph creation ScrolledComposite is always greater than equal to the current size of inner composite.

    Hope this helps.