How to make a window to be thin in SWT?

Why does the following application not allow me to make the window very thin? The minimum width allows 3 columns of images to be placed, while I want to make the width into one column.

enter image description here

How to allow narrowing more?

package tests;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class TryRowLayout {

    public static void main(String[] args) {

        RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
        rowLayout.wrap = true;





        Display display = new Display();

        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        shell.setMinimumSize(1, 1);
        //shell.setLayout(rowLayout);

        Composite composite = new Composite(shell, SWT.NONE);
        composite.setLayout(rowLayout);




        Image image = new Image(display, "images/alt_window_32.gif");

        Label label;
        for(int i=0; i<100; ++i) {
            //label = new Label(shell, SWT.NONE);
            label = new Label(composite, SWT.NONE);
            label.setImage(image);
        }



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

    }


}
+3
source share
1 answer

The reason for this is because Windows requires a minimum window width in order to be able to add min / max / close buttons and a window title.

The default style Shellis

SWT.SHELL_TRIM = SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE

Unfortunately, you can’t even get around this by Shellsimply showing the close button:

Shell shell = new Shell(display, SWT.CLOSE | SWT.RESIZE);

Windows will still apply the minimum width.


, , , . ,

Shell shell = new Shell(display, SWT.RESIZE);

:

public static void main(String[] args)
{
    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
    rowLayout.wrap = true;

    Display display = new Display();

    Shell shell = new Shell(display, SWT.RESIZE);
    shell.setLayout(new FillLayout());
    shell.setMinimumSize(1, 1);
    // shell.setLayout(rowLayout);

    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(rowLayout);

    Label label;
    for (int i = 0; i < 100; ++i)
    {
        // label = new Label(shell, SWT.NONE);
        label = new Label(composite, SWT.NONE);
        label.setText("A");
    }

    shell.pack();
    shell.open();
    shell.setSize(50, 200);
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

:

enter image description here

+5

All Articles