0

I have the following problem:
I'm using SWT to create a GUI for my application. I have a TabFolder in which I add several TabItems and in each of those I create a ScrolledComposite that holds some content.

The TabFolder is displaying fine, however the ScrolledComposite in the TabFolder does only show it's content in the first TabItem. All other ScrolledComposites are visible themselves just fine but their content is invisible.

Here is a little code snippet that demonstrates what I am referring to:

    Display display = new Display();

    Shell topShell = new Shell(display);

    topShell.setSize(800, 800);
    topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
    topShell.setLayout(new FillLayout());


    TabFolder folder = new TabFolder(topShell, SWT.NONE);

    for (int i = 0; i < 5; i++) {
        TabItem item = new TabItem(folder, SWT.NONE);
        item.setText("Item " + i);

        ScrolledComposite scroller = new ScrolledComposite(folder,
                SWT.H_SCROLL | SWT.V_SCROLL );

        scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

        Composite content = new Composite(scroller, SWT.NONE);
        content.setBackground(display.getSystemColor(SWT.COLOR_RED));

        scroller.setContent(content);
        scroller.setExpandHorizontal(true);
        scroller.setExpandVertical(true);

        item.setControl(scroller);
    }

    topShell.setVisible(true);

    while (!topShell.isDisposed()) {
        display.readAndDispatch();
    }

You can tell that the content is being displayed if the area is painted red. If the content is invisible the area is blue (the background of the ScrolledComposite)

I'm not sure if that matters but this occurs on Linux Mint 18 and it appears to only happen within GTK 3 (in 2 it works just fine)

After quite some time I tracked the issue down to the following:
It turned out that the problem was that the "missing" content had a size of zero, because the layouting doesn't set the size of those.

In my case it could be fixed by removing the SWT.V_SCROLL and the SWT.H_SCROLL style constants from the ScrolledComposite. Therefore the above code written as following works as expected.

    Display display = new Display();

    Shell topShell = new Shell(display);

    topShell.setSize(800, 800);
    topShell.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
    topShell.setLayout(new FillLayout());


    TabFolder folder = new TabFolder(topShell, SWT.NONE);

    for (int i = 0; i < 5; i++) {
        TabItem item = new TabItem(folder, SWT.NONE);
        item.setText("Item " + i);

        ScrolledComposite scroller = new ScrolledComposite(folder,
                SWT.NONE);

        scroller.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

        Composite content = new Composite(scroller, SWT.NONE);
        content.setBackground(display.getSystemColor(SWT.COLOR_RED));

        scroller.setContent(content);
        scroller.setExpandHorizontal(true);
        scroller.setExpandVertical(true);

        item.setControl(scroller);
    }

    topShell.setVisible(true);

    while (!topShell.isDisposed()) {
        display.readAndDispatch();
    }

Although that causes all content to be properly sized it completely removes the ScrollBars of the ScrolledComposite which somehow is not what you want from a ScrolledComposite.

Does anyone know how to fix that or whether that is a bug (that might have been fixed in newer SWT versions)?

Raven
  • 2,951
  • 2
  • 26
  • 42
  • Does the `TabFolder` actually affect the behavior of the `ScrolledComposite`? On Windows, I can't see a difference after removing the `TabFolder` and making the shell the parent of the `ScrolledComposite.`. – Rüdiger Herrmann Aug 14 '17 at 08:55
  • I'm not exactly sure... The only thing that I can tell is that I have experienced the behaviour that on the first TabItem everything works as expected and on all other items the ScrolledComposite takes the proper site but the Composite inside the ScrolledComposite has a size of zero until resizing the complete window... – Raven Aug 14 '17 at 13:17

1 Answers1

0

I've fixed bugs related to this a few months ago.

Can you try latest SWT master? http://download.eclipse.org/eclipse/downloads/

Leo Ufimtsev
  • 6,240
  • 5
  • 40
  • 48
  • Yes indeed that fixed the problem. Without chaning anything it should use GTK 3 shouldn't it? If that is the case the problem is resolved. – Raven Aug 21 '17 at 15:54
  • Yea, current default is Gtk3 (unless you don't have Gtk3 installed, in which case it falls back to Gtk2. You can find out by help > about > right click "copy build info to clipboard. Prints gtk version used. – Leo Ufimtsev Aug 21 '17 at 18:20