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.
Решение
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))
Другие советы
You can manually fire an event. If you are using ComponentListener then you can use one of the methods listed in this interface, see http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/event/ComponentListener.html.