0

I am facing an issue with editor and its contents layout. Its following: there is an editor with print preview functionality, main part of the editor is taken by paper clips PrintPreview component, on the left side there is a composite with some buttons (see screenshot 1).

screenshot 1

As you can see PrintPreview is located inside ScrolledComposite.

The problem is: when I am resizing window or views under editor, the bottom scrollbar moves under views and thus disappears. There is no way to scroll horizontally afterwards (no editor scrollbar appears). see screenshot2 (bottom scrollbar is getting hidden).

It starting to get hidden, when editor height is less then height of the right composite ( there are more widgets below the last button, I've just erased them)

screenshot 2

If I am shrinking the window, then right composite never loses its width and always visible (see screenshot 3 - It does not allow to resize more than that).

screenshot 3 The composites are created in the following way:

   @Override
    public void createPartControl(final Composite parent) {

        GridLayout gridLayout = new GridLayout(2, false);
        parent.setLayout(gridLayout);

        // Scroll area for the print area
        scroll = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
        final GridData gridData = new GridData(GridData.FILL_BOTH);
        gridData.grabExcessHorizontalSpace = true;
        gridData.grabExcessVerticalSpace = true;
        gridData.widthHint = 1;
        gridData.heightHint = 1;
        scroll.setLayoutData(gridData);
        scroll.setExpandHorizontal(true);
        scroll.setExpandVertical(true);

// Button area
        final Composite buttonArea = new Composite(parent, SWT.FLAT);
        final GridData layoutData = new GridData(SWT.FILL, SWT.TOP, false, false);
        buttonArea.setLayoutData(layoutData);
        gridLayout = new GridLayout(1, false);
        buttonArea.setLayout(gridLayout);

The question is: how not to prevent disappearing of the bottom scrollbar? Can I have the same behavior as width the width of the right composite - It not possible to resize less then right composite height? Or how can I show scrollbar on the whole editor if some minimum height limit is exceeded?

I've tried different things on different composites, like setting minimumHeight and heightHint, putting buttonsArea into the scrolledcomposite (just for fun) etc. But nothing have helped me.

Does anybody knows fast solution? Thank you.

Alex K.
  • 3,294
  • 4
  • 29
  • 41

1 Answers1

2

See this SO post: Prevent SWT scrolledComposite from eating part of it's children

You need to listen for width changes on the content composite (mParent), compute the minimum height again given the new content width, and call setMinHeight() on the scrolled composite with new height.

If the above post is not as useful as it seems then share some minimal compiling and executable code to replicate the problem. Also, mention the eclipse/swt version, OS and JDK version, it helps in analyzing the problem.


Demo code for resize event and output !!

Code :

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class ScrolledCompositeTest
{
    public static void main (String [] args)
    {
          Display display = new Display ();
          Shell shell = new Shell (display);
          shell.setLayout(new FillLayout());

          GridLayout layout = new GridLayout();
          layout.numColumns = 4;

          // set the minimum width and height of the scrolled content - method 2
          final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
          sc2.setExpandHorizontal(true);
          sc2.setExpandVertical(true);
          final Composite c2 = new Composite(sc2, SWT.NONE);
          sc2.setContent(c2);
          layout = new GridLayout();
          layout.numColumns = 7;
          c2.setLayout(layout);
          Button b2 = new Button (c2, SWT.PUSH);
          b2.setText("first button");
          sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));

          Button add = new Button (shell, SWT.PUSH);
          add.setText("add children");
          final int[] index = new int[]{0};
          add.addListener(SWT.Selection, new Listener() {
              public void handleEvent(Event e) {
                  index[0]++;
                  Button button = new Button(c2, SWT.PUSH);
                  button.setText("button "+index[0]);
                  sc2.setMinSize(c2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                  c2.layout();
              }
          });

          shell.open ();
          while (!shell.isDisposed ()) {
              if (!display.readAndDispatch ()) display.sleep ();
          }
          display.dispose ();
     }
}

Output:

Actual Size

enter image description here

Vertical Resize

enter image description here

Horizontal Resize

enter image description here

Community
  • 1
  • 1
Favonius
  • 13,959
  • 3
  • 55
  • 95
  • Thank you for your answer! I've tried your solution and it is working. Thou I have already solved this issue by changing layout data of button area to grabExcessVerticalSpace=true and adding GridData to all children with verticalAlign=FILL. From the first glance it seem to have the same behavior, thou not so elegant probably. Cheers – Alex K. Mar 06 '12 at 07:56