Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

why so many document listener events?

Thread view: 
Wizumwalt@gmail.com - 16 May 2006 23:14 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.