You need to add a DocumentListener to a Document that supports the text area.
Then, in the callback methods (insertUpdate (), removeUpdate (), changedUpdate ()) of the listener, simply set the flag that changed something, and check this flag before closing the application
public class MyPanel
implements DocumentListener
{
private boolean changed;
public MyPanel ()
{
JTextArea textArea = new JTextArea ();
textArea.getDocument (). addDocumentListener (this);
.....
}
.....
public void insertUpdate (DocumentEvent e)
{
changed = true;
}
public void removeUpdate (DocumentEvent e)
{
changed = true;
}
public void changedUpdate (DocumentEvent e)
{
changed = true;
}
}
source share