SWT Java: How to prevent window from resizing?

↘锁芯ラ 提交于 2019-11-30 08:27:05

问题


I want to disable resizing of window. Any ideas?


回答1:


You can specify the Shell style bits by using the two-arg constructor. The default style bits are SWT.SHELL_TRIM:

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

You actually want to exclude the RESIZE bit. If you're creating your own Shell:

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

If you're extending Dialog, you can influence the shell style bits by overridding getShellStyle:

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



回答2:


You can control the furniture when you declare the shell. I think this example does what you want;

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



回答3:


I'm not sure about it, but I think you can just drop SWT.Resize event like this:

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


来源:https://stackoverflow.com/questions/7740387/swt-java-how-to-prevent-window-from-resizing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!