SWT Java:如何防止窗口调整大小?

时间:2011-10-12 12:55:05

标签: java resize window swt

我想禁用窗口大小调整。有什么想法吗?

3 个答案:

答案 0 :(得分:28)

您可以使用two-arg构造函数指定Shell样式位。默认样式位为SWT.SHELL_TRIM

public static final int SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE;

您实际上想要排除RESIZE位。如果您要创建自己的Shell

final Shell shell = new Shell(parentShell, SWT.SHELL_TRIM & (~SWT.RESIZE));

如果您正在扩展Dialog,则可以通过覆盖getShellStyle来影响shell样式位:

@Override
protected int getShellStyle()
{
    return super.getShellStyle() & (~SWT.RESIZE);
}

答案 1 :(得分:5)

您可以在声明外壳时控制家具。我认为这个例子符合你的要求;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class FixedWindow {
    public static void main(String[] args) {
        Display display = new Display();

        //final Shell shell = new Shell(display); //defaults
        //final Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX); //can be maximised
        final Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN ); // fixed but can be minimised
        //final Shell shell = new Shell(display,  SWT.TITLE ); // fixed, uncloseable, unminimisable can only be removed by OS killing JVM.

        Rectangle boundRect = new Rectangle(0, 0, 1024, 768);
        shell.setBounds(boundRect);
        Rectangle boundInternal = shell.getClientArea();

        shell.setText("Fixed size SWT Window.");

        shell.open();

        final Text text = new Text(shell, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);

        text.setEditable(true);
        text.setEnabled(true);
        text.setText("Oh help!");
        text.setBounds(boundInternal);


        while (!shell.isDisposed()) {

            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

答案 2 :(得分:-2)

我不确定,但我认为你可以放弃SWT.Resize事件:

shell.addListener (SWT.Resize, new Listener () {
    public void handleEvent (Event e)
    {
       return;
    }
});