Search code examples
javalisteners

Forcing listener execution


I have a problem.

I have an object with a listener attached to it.

I'd like to be able to manually execute it, somehow trick it that the event that triggers it occurred. Maybe there's a way to access the specific listener and tell it to execute?

Object is Box.Filler and listener is ComponentListener (adapter, acctually). It's activated on ComponentResized event.


Solution

  • Well if you were using ComponentListener my guess is you could call it directly:

    listener.componentResized(new ComponentEvent (this,id))
    

    If you were using an adapter

    adapter.componentResized(new ComponentEvent (this,id))
    

    If your class implements ComponentListener

    componentResized(new ComponentEvent (this,id))