Maximizing a JFace dialog programmatically

A short snippet to show you how to maximize a JFace dialog.
If you have googled it, you must have heard about the method setMaximized of the Shell class. However, you have to call this method at the right place in your code. Otherwise, it will not work.

The secret is to invoke this method on the dialog’s shell only once this shell has been created. You cannot configure it before. I have struggled a long time to understand why Shell#setMaximized did not work when invoked from Dialog#createContents(Composite). At least, it does not work on Windows 7. Eventually, I found it. The solution is to invoke it in Dialog#constrainShellSize().

public class ApplicationUI extends ApplicationWindow {

	public ApplicationUI() {
		super( null );
		// ...

	protected void constrainShellSize() {
		getShell().setMaximized( true );

	// ...

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s