eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
112 stars 134 forks source link

Tab is not getting resized in TabFolder on tab title changed even after .layout() and .redraw() called #746

Open fyudanov opened 1 year ago

fyudanov commented 1 year ago

Describe the bug On changing tab title with tab.setText(), the tab is not getting resized even after shell.layout() or shell.redraw() call. It's getting resized properly only on explicit dialog resize (manual or pragmatical with shell.setSize()).

This is not happening in case of FormLayout applied to Shell, seems to be only reproducible for GridLayout with GridData.FILL_BOTH on TabFolder..

To Reproduce Snippet:

package tabsIssueSnippet;

import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class TabsIssueSnippet {

    public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("Tab Text Resizing Issue Snippet");

        final int insetX = 4, insetY = 4;
        GridLayout formLayout = new GridLayout();
        formLayout.marginWidth = insetX;
        formLayout.marginHeight = insetY;
        shell.setLayout(formLayout);

        TabFolder client = new TabFolder(shell, SWT.NONE);
        client.setLayoutData(new GridData(GridData.FILL_BOTH));

        TabItem tab1 = new TabItem(client, SWT.NONE);
        TabItem tab2 = new TabItem(client, SWT.NONE);

        Composite tab1Client = new Composite(client, SWT.NONE);
        GridLayout layout = new GridLayout(1, false);
        tab1Client.setLayout(layout);
        tab1.setControl(tab1Client);

        Composite tab2Client = new Composite(client, SWT.NONE);
        layout = new GridLayout();
        tab2Client.setLayout(layout);
        tab2.setControl(tab2Client);

        tab1.setText("Tab1");
        tab2.setText("Tab2");

        Button button = new Button(shell, SWT.PUSH);
        button.setText("Set long tab name");

        button.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent e) {
                Display.getDefault().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        tab1.setText("Looooooooong");
                        shell.layout();
                        shell.redraw();
                    }
                });
            }
        });

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

Expected behavior shell.layout() call should resize tab according to it's current title size.

Screenshots 6gjWjwuPqw

Environment

  1. Select the platform(s) on which the behavior is seen:

      • [ ] All OS
      • [ ] Windows
      • [ ] Linux
      • [x] macOS
  2. Additional OS info: MacOS 10.13; 12.6

  3. JRE/JDK version: JDK 20.

Version since Known to be reproducible on SWT 3.120 and SWT 4.28.

Workaround (or) Additional context Explicit window resizing helps.

iloveeclipse commented 1 year ago

Just curious, have you checked if that works in CTabFolder?

elsazac commented 1 year ago

@iloveeclipse

I tried it with this snippet. CTabFolder works fine.

package org.eclipse.swt.bug;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class CTabsIssueSnippet {
    public static void main(String[] args) {
        Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("Tab Text Resizing Issue Snippet");
        final int insetX = 4, insetY = 4;
        GridLayout formLayout = new GridLayout();
        formLayout.marginWidth = insetX;
        formLayout.marginHeight = insetY;
        shell.setLayout(formLayout);

        CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
        for (int i = 0; i < 4; i++) {
            CTabItem item = new CTabItem(folder, SWT.CLOSE);
            item.setText("Item "+i);
            Text text = new Text(folder, SWT.MULTI);
            text.setText("Content for Item "+i);
            item.setControl(text);
        }
        final CTabItem specialItem = new CTabItem(folder, SWT.CLOSE);
        specialItem.setText("Don't Close Me");
        Text text = new Text(folder, SWT.MULTI);
        text.setText("This tab can never be closed");
        specialItem.setControl(text);
        folder.addCTabFolder2Listener(CTabFolder2Listener.closeAdapter(event -> {
            if (event.item.equals(specialItem)) {
                event.doit = false;
            }
        }));
        final CTabItem noCloseItem = new CTabItem(folder, SWT.NONE);
        noCloseItem.setText("No Close Button");
        Text text2 = new Text(folder, SWT.MULTI);
        text2.setText("This tab does not have a close button");
        noCloseItem.setControl(text2);

        Button button = new Button(shell, SWT.PUSH);
        button.setText("Set long tab name");
        button.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(final SelectionEvent e) {
                Display.getDefault().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        noCloseItem.setText("Loooooooooooooooong");
                        shell.layout();
                        shell.redraw();
                    }
                });
            }
        });
        shell.setSize(800, 200);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

This is the output:

Screenshot 2023-07-14 at 12 25 58 PM

Tried on : Eclipse SDK Version: 2023-09 (4.29) Build id: I20230705-1800 OS: Mac OS X, v.13.4.1, aarch64 / cocoa Java vendor: Eclipse Adoptium Java runtime version: 17.0.6+10 Java version: 17.0.6

elsazac commented 1 year ago

But Tab is not getting resized.

image
deepika-u commented 1 year ago

Hi,

image

image

Both TabFolder and CTabFolder works fine on windows. Tried on below environment Eclipse SDK Version: 2023-09 (4.29) Build id: I20230712-1800 OS: Windows 11, v.10.0, x86_64 / win32 Java vendor: Eclipse Adoptium Java runtime version: 20+36 Java version: 20

fedejeanne commented 5 months ago

Works as expected on Linux too

Screenshot from 2024-04-20 06-57-14

Screenshot from 2024-04-20 06-58-11

Environment

Eclipse SDK Version: 2024-06 (4.32) Build id: I20240327-1800 OS: Ubuntu 20.04 (x86_64) / X11 / GNome 3.36.8 java.version=17.0.7 java.vendor=Amazon.com Inc.