如何使窗口能够在SWT中变薄?

Dim*_*ims 3 java swt

为什么以下应用程序不允许我使窗口非常薄?最小宽度允许布置3列图像,同时我希望能够实现单列宽.

在此输入图像描述

如何缩小更多?

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();
        }

    }


}
Run Code Online (Sandbox Code Playgroud)

Baz*_*Baz 5

原因是Windows需要最小窗口宽度才能添加最小/最大/关闭按钮和窗口标题.

默认样式Shell

SWT.SHELL_TRIM = SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE
Run Code Online (Sandbox Code Playgroud)

不幸的是,你甚至无法通过强制Shell显示关闭按钮来解决这个问题:

Shell shell = new Shell(display, SWT.CLOSE | SWT.RESIZE);
Run Code Online (Sandbox Code Playgroud)

Windows仍将强制执行最小宽度.


最后,如果你仍然需要窗口控件,我担心你无能为力.如果您不需要窗口控件,那么您可以使用

Shell shell = new Shell(display, SWT.RESIZE);
Run Code Online (Sandbox Code Playgroud)

这是示例代码:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是它的样子:

在此输入图像描述