Regarding Noel's comment:
The problem with this method being triggered is that a particular listener implementation returns a notification earlier and does the work out of band in a separate thread. In this case, the end of the notification call does not actually indicate the end of the listener's execution. If this is an actual issue (i.e. you are aware and interested in other custom, thoughtful listeners who do such things, you may need to clarify and revise the issue.
Using SwingUtilities.invokeLater() , you are sure that the code is executed after notifying all listeners. But one of these listeners can do this work in a separate thread.
If you need to execute your code after all the listeners have not only been notified, but also finished, you can do something like this:
<sub> pseudo-code: sub>
Listener implements MouseListener +mouseClicked( event: MouseEvent ) SwingUtilities.invokeLater(
If you have your listeners like
addListener( new Listener() ) addListener( new Listener() ) addListener( new Listener() ) addListener( new ExecuteAtTheEnd() )
If all (or some) of your listeners do their work in another thread. Your ExecuteAtTheEnd can execute its code at the end of the notification, but not at the end of the listeners code execution.
So what are you doing?
You need to synchronize the use of some lock flag and execute your code until this flag is used.
It can be a counter that increases when the listener executes and decreases the value if it is not:
Listener implements MouseListener +mouseClicked( event: MouseEvent ) lockFlagCount++ SwingUtilities.invokeLater( someTask() ) -someTask()
And then you just continue until this flag is false:
ExecuteAtTheEndListener implements MouseListener + mouseClicked( event: MouseEvent ) SwingUtilities.invokeLater( executeAtTheEnd() ) - executeAtTheEnd() while( logFlagCount > 0 ) wait() if( logFlagCount == 0 )
Of course, this is much more complicated since I put it in pseudo-code, but it should work if you are in such circumstances.