Java SwingUtilities.invokeLater() timing with drag and drop

316 views Asked by At

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?

2

There are 2 answers

1
Jeffrey On BEST ANSWER

The way invokeLater works is that it adds your Runnable 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 for invokeLater 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.

2
trashgod On

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.