【发布时间】:2011-12-06 02:59:42
【问题描述】:
我想禁用调整窗口大小。有什么想法吗?
【问题讨论】:
我想禁用调整窗口大小。有什么想法吗?
【问题讨论】:
您可以使用双参数构造函数指定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);
}
【讨论】:
您可以在声明外壳时控制家具。我认为这个例子可以满足你的要求;
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;
}
});
【讨论】:
e.doit 设置为 false 无效。在某些平台上,您可以尝试将 shell 的大小 back 设置为原来的大小,但这在某些平台上看起来很奇怪(尤其是线框调整大小,或者允许在触发前进行大量调整的平台该事件。)在其他平台上,当您在调整大小侦听器中调整外壳大小时,您实际上会得到一个无限循环的事件(除非您设置了一个正在更改大小的标志。)