简体   繁体   English

Java SWT中的Resizeble Dialog

[英]Resizeble Dialog in Java SWT

I have a Composite(container) which is inside another composite(Dialog area). 我有一个复合(容器)在另一个复合(对话区域)内。 The container contains some UI elements. 容器包含一些UI元素。 How can I either make the size of the dialog bigger or make it resizeable. 如何使对话框的大小更大或使其可调整大小。 Here is my code 这是我的代码

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

To make a JFace dialog resizable add an override for the isResizable method: 要使JFace对话框可调整大小,请为isResizable方法添加覆盖:

@Override
protected boolean isResizable() {
    return true;
}

To make the dialog larger when it opens you can set a width or height hint on the layout. 要在打开时使对话框变大,可以在布局上设置宽度或高度提示。 For example: 例如:

GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
data.widthHint = convertWidthInCharsToPixels(75);
txtUsername.setLayoutData(data);

or you can override getInitialSize() , for example this code is leaving space for more characters both horizontally (75 characters) and vertically (20 lines): 或者你可以覆盖getInitialSize() ,例如这段代码为水平(75个字符)和垂直(20行)的更多字符留出空间:

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

    size.x = convertWidthInCharsToPixels(75);

    size.y += convertHeightInCharsToPixels(20);

    return size;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM