2
votes

I am at the beginning with GUI programming in JFace/SWT. Before I worked with an normal SWT window (http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.wb.ercp.doc.user%2Fhtml%2Fwizards%2FeRCP%2Fapplication_window.html) and today I've tried the JFace Application Window for the first time.

Now I want to set a minimum size of this window.. In SWT it worked with

shell.setMinimumSize(100,100)

but in my the org.eclipse.jface.window.ApplicationWindow there is no such method..

I've tried

this.createShell().setMinimumSize(100, 100);

(my implementation "public class MainView extends ApplicationWindow {")

but it doesn't work.

this.getShell()

returns null.

By the way, I searched for a good documentation about JFace in gernal, for now especially for the Application Window. But I couldn't find anything really good and extensive.

The documentation in SWT, especially JFace is very dispairing.. Too bad, because there are nice features in it.

What are your experiences?

2

2 Answers

4
votes

Override the configureShell method and set the minimum size there:

@Override
protected void configureShell(Shell newShell)
{
  super.configureShell(newShell);

  newShell.setMinimumSize(100, 100);
}
0
votes

As you can see from the documentation of the createShell method, it creates a new shell. You need to use existing/created shell of your window.

You can get it from the parent composite of your application. Please see the createContents method in the following snippet:

package helloproject;

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

public class HelloWorld extends ApplicationWindow {

    public HelloWorld() {
        super(null);
    }

    /**
     * Runs the application
     */
    public void run() {
        setBlockOnOpen(true);
        open();
        Display.getCurrent().dispose();
    }

    protected Control createContents(Composite parent) {
        // Create a Hello, World label
        Label label = new Label(parent, SWT.CENTER);
        label.setText("Hello, World");

        // Set the minimum size
        parent.getShell().setMinimumSize(200, 200);

        return label;
    }

    public static void main(String[] args) {
        new HelloWorld().run();
    }
}