eclipse-platform / eclipse.platform.swt

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

SWT window size is not correct (partial window size) #770

Open leiless opened 1 year ago

leiless commented 1 year ago

Describe the bug Hi all, I created a Shell, and populate its content, open the window. But the window size is incorrect sometimes in some Linux distros (Like Manjaro, Fedora).

Originally reported at https://bugs.eclipse.org/bugs/show_bug.cgi?id=577515

To Reproduce

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Event;

public class Main {
    private static final class MyShell extends Shell {
        private final Shell parent_;

        private void createContents() {
            setSize(400, 400);
            setText("Hello");
            Button button = new Button(this, SWT.NONE);
            button.setText("Button");
            button.setLocation(150, 150);
            button.pack();

            addListener(SWT.Close, new Listener() {
                public void handleEvent(Event event) {
                    parent_.close();
                }
            });
        }

        public MyShell(Shell parent) {
            super(parent, SWT.CLOSE | SWT.MIN | SWT.TITLE);
            parent_ = parent;
            setLayout(null);
            createContents();
        }

        @Override
        protected void checkSubclass() {
            // Disable the check that prevents subclassing of SWT components
        }
    }

    public static void main(String[] args) {
        System.out.println("SWT.getVersion(): " + SWT.getVersion());

        Display display = new Display();
        Shell shell = new Shell(display);
        //shell.setText("SWT Browser Test");
        //shell.setLayout(new FillLayout());

        MyShell myShell = new MyShell(shell);
        myShell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}
javac -cp ./swt.jar Main.java && java -cp .:./swt.jar Main

Expected behavior The window size should always be in the correct size(specified in the Java code).

Screenshots 1

Environment:

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

      • [x] Linux
  2. Additional OS info (e.g. OS version, Linux Desktop, etc) OS: Ubuntu 22.04.3 LTS x86_64 SWT: swt-4.24M1.jar

  3. JRE/JDK version

    $ java -version                      
    openjdk version "11.0.20" 2023-07-18
    OpenJDK Runtime Environment (build 11.0.20+8-post-Ubuntu-1ubuntu122.04)
    OpenJDK 64-Bit Server VM (build 11.0.20+8-post-Ubuntu-1ubuntu122.04, mixed mode, sharing)

Version since SWT 4.24

Workaround (or) Additional context FYI, I can fix this bug (as a workaround) by adding the SWT.RESIZE to the window style, and the window will appear as its setSize(x, y) size.

mickaelistria commented 1 year ago

Thanks. Could you please try to turn this snippet into an automated test in the existing test bundle/suite of this repository and contribute a PR that runs this test?

tmssngr commented 1 year ago

Could this problem be related to the existence of or values inside ~/.swt/trims.prefs?

leiless commented 1 year ago

In which circumstance does the ~/.swt/trims.prefs exist?

If it's a preferences file, then no, I'm not using this file.

openaudible commented 7 months ago

I'm seeing this running OpenAudible on Debian 12.5. Using the GridLayout for all layouts. Not using GridData widthHints but using minimumWidths to hint the size of the text. Lots of columns are the wrong size-- especially with regard to text. Not sure how best to debug.. but will be looking into this more. Using latest 3.124.200 SWT.