When you do drag and drop of a object, what happens to all its listeners?
When the object is serialized in order to do drag (MOVE), the listeners are registered to the copy of the object before the drag/serialization, not to the new one.
So, how to recreate/add the listeners to the new object?
I have an extensions of a JTextArea. I drag it and drop it in another Container. The previous listeners are still there, but they do not receive any event.
Since the listeners are added during the initializations not in my code, how can I remove them and re-add them so that they are added to the new one and not the old one. Also every time I drag it, one more listener is added.

Before drag: list of all listener:

Java Code:
getListeners(MouseListener.class);
Java Code:
dot=0,mark=0  class javax.swing.text.JTextComponent$MutableCaretEvent
javax.swing.plaf.basic.BasicTextUI$DragListener@5c061cd2  class javax.swing.plaf.basic.BasicTextUI$DragListener
Dot=(0, Forward) Mark=(0, Forward)  class javax.swing.plaf.basic.BasicTextUI$BasicCaret
mine listener
mouse 4

After drag
getListeners(MouseListener.class);

Java Code:
dot=0,mark=0  class javax.swing.text.JTextComponent$MutableCaretEvent
mine listener
dot=0,mark=0  class javax.swing.text.JTextComponent$MutableCaretEvent
javax.swing.plaf.basic.BasicTextUI$DragListener@5c061cd2  class javax.swing.plaf.basic.BasicTextUI$DragListener
Dot=(0, Forward) Mark=(0, Forward)  class javax.swing.plaf.basic.BasicTextUI$BasicCaret
mouse 5

After the drag, as you can see the MutableCaretEvent listeners is doubled, but one of them is not active. If I keep dragging and dropping around the JTextArea, the number of dead MutableCaretEvent listeners increases.

How can I eliminate the ones that do not work anymore and add new ones again?


I do have in the code the following:
Java Code:
	public void updateListeners() {
		this.getDocument().removeDocumentListener(docListener);
		docListener=new MyDocumentListener();
		this.getDocument().addDocumentListener(docListener);
	}
I can remove the listeners, but how can I add them if I didn't add them in the first place? Or how can I select the listeners that are dead?

Thanks