Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I actually unregister a document listener?  RSS feed

 
Thomas Kiersted
Greenhorn
Posts: 22
Opera Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought this was pretty straightforward with the removeDocumentListener method, but unfortunately, it is not removing my document listeners. I have tried two approaches. I have a class that I'll call MyDocumentListener, which implements DocumentListener, and is used in this code. There is a situation in my program where I want to remove document listeners. Here is my first approach to remove them:



I figured this would suffice to go through all the DocumentListeners attached to each JTextField, and remove all those that were MyDocumentListeners. Unfortunately, that is proving not to be the case.

So I tried a second approach:



Here I figured I'd iterate through all the MyDocumentListeners, and remove them from whichever JTextField they were attached to as I encountered them. I added them to the map as they were created, and the final debug statement does confirm that my map no longer contains any document listeners.

But in both cases, the MyDocumentListeners are still processing events and reacting to them. My attempts to cut them off from the flow of events have been in vain. Thus, rather than continue to as further attempts to solve this fail, I thought I'd ask here: how, exactly, do I remove a document listener?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DO you have reason to believe that removeDocumentListener() is ever actually being called? For example, do you ever see the "removing a length document listener" debug message? One possibility is that the removeDocumentListener() calls are never actually happening; for example, because textBoxes is actually an empty list.

Add some more debug prints, or trace through the code with a debugger, and find out whether anything is actually being removed.
 
Thomas Kiersted
Greenhorn
Posts: 22
Opera Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the document listeners are definitely not being removed - they have visible effects on the GUI that are still occur even after their supposed removal. TextBoxes only appears empty as I didn't actually post the entire (partially) abstract class this code is from.

But does it look like I'm going about this in a sensible manner? Right now all the logging statements indicate my listeners should be gone, but going by the GUI they clearly are not removed. I guess I'll take it for a go through the debugger - better than nothing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!