简体   繁体   English

拖放Java SwingUtilities.invokeLater()计时

[英]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. Java Swing的SwingUtilities.invokeLater()允许您排队处理最后一个AWT事件(用户手势)之后运行的线程。

Is invokeLater() guaranteed to wait until after the completion of a drag and drop gesture? 是否可以确保invokeLater()等到拖放手势完成后才开始?

No, EventQueue guarantees two things for queued instances of Runnable : 不, EventQueue保证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 your Runnable to a list of objects that will be executed in sequence on the Event Dispatch Thread. invokeLater工作方式是将Runnable添加到将在事件调度线程上按顺序执行的对象列表。 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. EDT负责应用程序中触发的每个事件,包括鼠标事件,键事件,重绘等。为了使invokeLater等到拖放手势结束之前,DnD手势必须阻止EDT。直到完全完成。 This would also mean that your application would become completely unresponsive until the DnD gesture was finished. 这也意味着在DnD手势完成之前,您的应用程序将变得完全无响应。

So, no, invokeLater will not wait until your DnD gesture has finished. 因此,不, invokeLater 不会等到您的DnD手势完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM