SWT Java:如何防止窗口调整大小?
我想禁用窗口的大小调整。有什么想法吗?你可以在申报外壳时控制家具。我认为这个例子正是你想要的SWT Java:如何防止窗口调整大小?,java,resize,window,swt,Java,Resize,Window,Swt,我想禁用窗口的大小调整。有什么想法吗?你可以在申报外壳时控制家具。我认为这个例子正是你想要的 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.ec
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();
}
}
我不确定,但我认为您可以直接删除SWT.Resize事件,如下所示:
shell.addListener (SWT.Resize, new Listener () {
public void handleEvent (Event e)
{
return;
}
});
您可以使用双参数构造函数指定
Shell
样式位。默认样式位为SWT.SHELL\u TRIM:
public static final int SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE;
实际上,您希望排除调整大小
位。如果您正在创建自己的Shell
:
final Shell shell = new Shell(parentShell, SWT.SHELL_TRIM & (~SWT.RESIZE));
如果要扩展对话框
,可以通过重写getShellStyle
来影响shell样式位:
@Override
protected int getShellStyle()
{
return super.getShellStyle() & (~SWT.RESIZE);
}
可能是重复的感谢,实际上我同时通过添加:“new Shell(display,SWT.CLOSE | SWT.TITLE)”解决了这个问题,您的答案也是一样的,但另外还有一个问题这在实践中并不太有效-调整大小侦听器是在窗口调整大小之后启动的,而不是之前启动的,因此将
e.doit
设置为false没有任何效果。在某些平台上,您可以尝试将shell的大小设置回原来的大小,但在某些平台上(尤其是线框大小调整,或者在触发该事件之前允许大量调整大小的平台上),这看起来很奇怪。在其他平台上,当您在调整大小侦听器中调整shell大小时,实际上会出现无限的事件循环(除非设置要更改大小的标志。)