Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
SwingUtilities.invokeLater(Runnable)如果您正在修改 GUI 并且您在 AWT 事件调度线程中,您是否应该使用ActionListener?
SwingUtilities.invokeLater(Runnable)
ActionListener
您必须始终在事件调度线程 (EDT) 中进行 GUI 更新。然而,正如 Jeffrey 在评论中指出的那样,ActionListener.actionPerformedSwing 对象上的方法已经从 EDT 调用。
ActionListener.actionPerformed
如果您只是想让JButton看起来启用/未启用或从 中添加/删除项目JList,并且您通过 Swing 组件上的 进行这些更改ActionListener,那么您不必SwingUtilities.invokeLater显式调用。
JButton
JList
SwingUtilities.invokeLater