Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizeble Dialog in Java SWT

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;
}
like image 756
wearybands Avatar asked Dec 20 '22 09:12

wearybands


1 Answers

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;
}
like image 186
greg-449 Avatar answered Dec 22 '22 00:12

greg-449