MyDocumentListener implements the DocumentListener interface. The
problem I'm having with it is that when I start my GUI, the
insertUpdate() and removeUpdate() methods that I overrode are
constantly being called even though I don't type anything in the text
field that the listener is attached to. It's kinda causing havoc in
MyDocumentListener where I handle the input.
[code]
MyDocumentListener listener = new MyDocumentListener(...);
myTextField.getDocument().addDocumentListener(listener);
// ... interface methods in MyDocumentListener
public void insertUpdate(DocumentEvent de) {
// ...
}
public void changedUpdate(DocumentEvent de) {
// ...
}
public void removeUpdate(DocumentEvent de) {
// ...
}
[/code]
Supposedly these methods give notification that an insert or other
change happened in the document, but I didn't make any changes, yet
they're constantly being called.
Anyone know why this is or understand what's going on here. Any help
much appreciated.
Trung Chinh Nguyen - 17 May 2006 14:05 GMT
There's nothing wrong with the code. The problem might lie somewhere
else. It would be clearer if you can provide the contents of the update
methods.
> MyDocumentListener implements the DocumentListener interface. The
> problem I'm having with it is that when I start my GUI, the
[quoted text clipped - 28 lines]
> Anyone know why this is or understand what's going on here. Any help
> much appreciated.
Wizumwalt@gmail.com - 17 May 2006 18:26 GMT
Thanks, while trying to explain it in a bit more detail (and a good
nights sleep :). I found what it was. Thanks again.
alexandre_paterson@yahoo.fr - 18 May 2006 01:31 GMT
...
> Supposedly these methods give notification that an insert or other
> change happened in the document, but I didn't make any changes, yet
> they're constantly being called.
I don't have a precise answer to your problem but depending
on the API you're using and how you're using the Observer
pattern, you may more or less "legally" enter in an
non-stopping "event cascade" mode where many unnecessary
events are launched.
This is a well known shortcoming of the Observer pattern and
there exist papers on the subject. There are, of course,
workarounds.
One such paper can be found here:
http://www.gruntz.ch/papers/Observer.pdf
FWIW
--
(Don't pay attention to my .sig) Text file size: 1509 bytes
SHA1: bbfa3226005c2d4d04e3d72d49bfb1eb17e67f12
MD5: 38dfd87012a2754059a88341d66e2ef4