Java Swing's SwingUtilities.invokeLater()
allows you to enqueue a thread to run after the last AWT event (user gesture) is processed.
Is invokeLater()
guaranteed to wait until after the completion of a drag and drop gesture?
Java Swing's SwingUtilities.invokeLater()
allows you to enqueue a thread to run after the last AWT event (user gesture) is processed.
Is invokeLater()
guaranteed to wait until after the completion of a drag and drop gesture?
No, EventQueue
guarantees two things for queued instances of Runnable
:
The instances will be executed sequentially.
That execution will be in the same order as the instances are enqueued.
The way
invokeLater
works is that it adds yourRunnable
to a list of objects that will be executed in sequence on the Event Dispatch Thread. The EDT is responsible for every event that is fired in your application, including mouse events, key events, repaints, etc. In order forinvokeLater
to wait until the end of a Drag and Drop gesture, the DnD gesture would have to block the EDT until it was fully complete. This would also mean that your application would become completely unresponsive until the DnD gesture was finished.So, no,
invokeLater
will not wait until your DnD gesture has finished.