Resizeble Dialog in Java SWT
Asked Answered
P

1

5

I have a Composite(container) which is inside another composite(Dialog area). The container contains some UI elements. 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;
}
Pollster answered 31/10, 2014 at 11:2 Comment(0)
D
12

To make a JFace dialog resizable add an override for the isResizable method:

@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):

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

    size.x = convertWidthInCharsToPixels(75);

    size.y += convertHeightInCharsToPixels(20);

    return size;
}
Diarmid answered 31/10, 2014 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.