static void applySaveOnCloseMethod(Stage stage, String name){
        stage.setOnCloseRequest( ev -> {
            try {
                Preferences stagePreferences = PREFERENCES.node(name);
                if( stage.isMaximized() ){
                    stagePreferences.putBoolean(WINDOW_MAXIMIZED, true);
                } else {
                    stagePreferences.putBoolean(WINDOW_MAXIMIZED, false);
                    stagePreferences.putDouble(WINDOW_X_POS, stage.getX());
                    stagePreferences.putDouble(WINDOW_Y_POS, stage.getY());
                    stagePreferences.putDouble(WINDOW_WIDTH, stage.getWidth());
                    stagePreferences.putDouble(WINDOW_HEIGHT, stage.getHeight());
                }
                stagePreferences.flush();
            } catch (final BackingStoreException ex) {
                LOGGER.error(ex, "Could not flush preferences for window " + name);
            } 
        });
    }
Adds an OnCloseRequest handle to the window which will store the position, 
size and maximized status of the window. 

@param stage  the stage to read settings from
@param name   the name under which we store the settings
tool-parent/tool-core/src/main/java/com/speedment/tool/core/internal/util/WindowSettingUtil.java