gpt4 book ai didi

java - Java SWT中的“可调整大小”对话框

转载 作者:行者123 更新时间:2023-12-04 17:59:53 25 4
gpt4 key购买 nike

我有一个Composite(容器)在另一个Composite(对话框区域)内。该容器包含一些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对话框可调整大小,请添加isResizable方法的替代:

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

关于java - Java SWT中的“可调整大小”对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26673121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com