Search code examples
javaswingdrag-and-dropswingutilities

Java SwingUtilities.invokeLater() timing with drag and drop


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?


Solution

  • 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.