wea*_*nds 2 java swt dialog jface 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;
}
Run Code Online (Sandbox Code Playgroud)
要使JFace对话框可调整大小,请为该isResizable方法添加覆盖:
@Override
protected boolean isResizable() {
return true;
}
Run Code Online (Sandbox Code Playgroud)
要在打开时使对话框变大,可以在布局上设置宽度或高度提示.例如:
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
data.widthHint = convertWidthInCharsToPixels(75);
txtUsername.setLayoutData(data);
Run Code Online (Sandbox Code Playgroud)
或者你可以覆盖getInitialSize(),例如这段代码为水平(75个字符)和垂直(20行)的更多字符留出空间:
@Override
protected Point getInitialSize() {
final Point size = super.getInitialSize();
size.x = convertWidthInCharsToPixels(75);
size.y += convertHeightInCharsToPixels(20);
return size;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2647 次 |
| 最近记录: |