Question

I have created a Dialog using JFace and set it to resizable using SWT.RESIZE. But, it allows the user to resize it all the way to 0 rows where only the title bar is visible.

Is there a way by which I can restrict the user to resize up to a certain number of rows only?

Was it helpful?

Solution

Use Shell#setMinimumSize(int, int) like this:

public class MyDialog extends Dialog
{
    public static void main(String[] args)
    {
        new MyDialog(new Shell()).open();
    }

    public MyDialog(Shell parentShell)
    {
        super(parentShell);
        setShellStyle(SWT.RESIZE | SWT.DIALOG_TRIM);
    }

    @Override
    protected Control createDialogArea(Composite parent)
    {
        Composite container = (Composite) super.createDialogArea(parent);
        getShell().setMinimumSize(400, 300);

        new Button(container, SWT.PUSH).setText("Some content here");

        return container;
    }
}

This will restrict the user from reducing the size below a width of 400 and a height of 300.


Keep different screen resolutions in mind though, as an enforced minimal size might exceed the available screen size...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top