Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaSWT中的Resizeble对话框_Java_Dialog_Swt_Jface_Composite - Fatal编程技术网

JavaSWT中的Resizeble对话框

JavaSWT中的Resizeble对话框,java,dialog,swt,jface,composite,Java,Dialog,Swt,Jface,Composite,我有一个复合(容器),它位于另一个复合(对话框区域)内。容器包含一些UI元素。如何使对话框的大小变大或可调整大小。这是我的密码 protected Control createDialogArea(Composite parent) { setMessage("Enter user information and press OK"); setTitle("User Information"); Composite area = (Composite) super.cr

我有一个复合(容器),它位于另一个复合(对话框区域)内。容器包含一些UI元素。如何使对话框的大小变大或可调整大小。这是我的密码

 protected Control createDialogArea(Composite parent) {
    setMessage("Enter user information and press OK");
    setTitle("User Information");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Label lblUserName = new Label(container, SWT.NONE);
    lblUserName.setText("User name");

    txtUsername = new Text(container, SWT.BORDER);
    txtUsername.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtUsername.setEditable(newUser);
    txtUsername.setText(name);

    return area;
}

要使JFace对话框的大小可调整,请为
isResizeable
方法添加覆盖:

@Override
protected boolean isResizable() {
    return true;
}
要使对话框在打开时变大,可以在布局上设置宽度或高度提示。例如:

GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
data.widthHint = convertWidthInCharsToPixels(75);
txtUsername.setLayoutData(data);
或者您可以重写
getInitialSize()
,例如,此代码在水平方向(75个字符)和垂直方向(20行)上为更多字符留出空间:

@Override
protected Point getInitialSize() {
    final Point size = super.getInitialSize();

    size.x = convertWidthInCharsToPixels(75);

    size.y += convertHeightInCharsToPixels(20);

    return size;
}