Its been a long time since I worked with Swing - but couldnt you have your listener object which controls the behaviour ? You could maintain a File object reference - if this is null, show up a file dialog, get the file reference and save to disk. On subsequent saves, since you have a File reference already,
you should simply write to the same stream rather than bringing up a dialog.
I know I did a
Java Text Editor some time ago - shall try to get you the relevant code.