jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Checking saved or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Checking saved or not" Watch "Checking saved or not" New topic

Checking saved or not

ashok kandaswamy

Joined: Aug 19, 2008
Posts: 16
hi ,
i am developing one smart word processor in java siwng,for load and save operation am using filechossers.

i am supporting multiple documents also using tabbedpane.i want to do when typing something on the document and without save that we will close the application means i want to do the save operation here.

please help very urgent,

thanks in advance.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i am supporting multiple documents

depends on how many 'multiple' is.

here's a basic scenario for a single doc:

(class field) boolean dirtyData = false;
- add a document listener to the doc - it's job is to make dirtyData = true;
- in your save() method, include dirtyData = false;
- set the default close operation of the frame to DO_NOTHING_ON_CLOSE
- add a windowListener to the frame, and in windowClosing() check if dirtyData
is true, if so, call save() (or ask user if save() wanted), then System.exit(0);

there was a recent-ish thread on this subject (past 4-6 weeks), with other options.
a quick search of this forum should find it.
I agree. Here's the link: http://aspose.com/file-tools
subject: Checking saved or not
It's not a secret anymore!