removing mouseListener

Hi,

i have a table and have added to the header some mouselistener on it.

How can i remove it ?

Code example.

JTable.getTableHeader().addMouseListener(new MouseAdapter ()

{public void mousePressed( MouseEvent event )

{

rightMouseClicked( event );

}

});

How can i remove this listener ?

Regards.

[369 byte] By [Wolfstone] at [2007-9-27 22:04:32]
# 1

You can't.

Since you lack the reference to the innerclass object, there is no way for you to remove it.

The alternative would be to do:

MouseListener ml = new MouseAdapter ()

{

public void mousePressed( MouseEvent event )

{

rightMouseClicked( event );

}

});

jtable.getTableHeader().addMouseListener(ml);

Now you can later use ml reference to remove it as listener.

Example:

jtable.removeTableHeader().addMouseListener(ml);

bithir at 2007-7-7 12:02:19 > top of Java-index,Archived Forums,Swing...