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

发布于 2024-12-09 07:56:44 字数 25 浏览 0 评论 0原文

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

I want to disable resizing of window. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云胡 2024-12-16 07:56:44

您可以使用两个参数的构造函数来指定 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);
}

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);
}
故事↓在人 2024-12-16 07:56:44

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

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

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();
    }
}
我恋#小黄人 2024-12-16 07:56:44

我不确定,但我认为你可以像这样删除 SWT.Resize 事件:

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

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;
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文