Eric Bergman-Terrell's Blog

Java Programming Tip: Make a JFace Dialog remember its size and position
December 11, 2008

One can easily set up JFace dialogs to remember their size and position. Furthermore, if the dialog was previously partially off the screen, it will be moved to be fully visible. Just do the following:

  1. Add a DialogSettings member
  2. Implement getDialogBoundsSettings() that returns the DialogSettings object.
  3. Implement getDialogBoundsStrategy() and have it return DIALOG_PERSISTLOCATION | DIALOG_PERSISTSIZE.
  4. Override close(). After the call to super.close(), call the DialogSetings object's save method.
  5. In your dialog's constructor, instantiate the DialogSettings object and call its load method.

For example:

package mainPackage;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogSettings;

public class ExampleDialog extends Dialog {
private final String settingsFilename = "ExampleDialog.txt";

DialogSettings dialogSettings;

    protected IDialogSettings getDialogBoundsSettings(){
        return dialogSettings;

    protected int getDialogBoundsStrategy(){

public boolean close() {
    boolean result = super.close();
    try {;
} catch (IOException e) {
// TODO Auto-generated catch block

return result;

public ExampleDialog(Shell parentShell) {

dialogSettings = new DialogSettings("settings");

try {
} catch (IOException e) {
// TODO Auto-generated catch block

this.setShellStyle(getShellStyle() | (SWT.RESIZE | SWT.SHELL_TRIM));
Keywords: Java, Eclipse, JFace, Dialog, SWT

Reader Comments

Comment on this Blog Post

Recent Posts

EBTCalc Users: A Desktop Version is Now Available!October 25, 2019
Python Script to Audit MediaMonkey TranscodingAugust 15, 2019
How to decompile Java code with JetBrains IntelliJ IDEA (2018.2.3, Windows 10)October 5, 2018
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016