- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
只是一个关于 SwingUtilities.InvokeLater() 的问题。
据我了解,每次更新 Swing 界面时,我都需要调用 SwingUtilities.InvokeLater 才能进入 EDT。如果我尝试从按钮监听器更新 GUI,是否需要执行此操作,因为按钮事件已在 EDT 上?
也就是说,我必须......
public void mouseClicked(MouseEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//GUI updates
}
});
}
或者我是否能够...
public void mouseClicked(MouseEvent e) {
//GUI updates
}
此外,如果我在对象上调用将更新 GUI 的方法,是否应用相同的逻辑?
最佳答案
any time I update my Swing interface I need to call SwingUtilities.InvokeLater to get onto the EDT
正确。这包括您更新组件模型的任何时间,因为这也会导致组件的重新绘制。
Does this need to be done if I am attempting to update my GUI from a button listener, as they button events are already on the EDT?
再次正确。由于代码会在 EDT 上自动调用,因此您无需使用 invokeLater() 手动将其添加到 EDT。
如果您的代码在单独的线程
上执行并且部分逻辑需要更新 GUI 组件,则通常使用 SwingUtilities.invokeLater()。
关于java - SwingUtilities.InvokeLater 和 ButtonListeners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53002147/
有人可以强调这两者之间的区别以及两者都是必需的实例吗?! 我有一个可以互换使用的应用程序,但想知道一个是否比另一个更好。显然它们都接受 Runnable object,所以对我来说 - 我想我可以使用
EventQueue.invokeLater() 和 SwingUtilities.invokeLater() 有什么不同吗? 或者是后者只是为了设计而建立在前者之上(没有修改)? 最佳答案 没有没有
在我的方法 doWork() 中,我调用 SwingUtilities.invokeLater(new Runnable(){ public void run() { button.setBackgr
我怎么感觉SwingUtilities.invokeLater()在任何swing应用中的必要性。请给出一些代码示例。 最佳答案 每当您需要更新 GUI 中的某些内容时,您应该通过 AWT 事件线程
.addActionListener(new ActionListener(){ public void actionPerformed (ActionEvent e){
我按照教程创建了一个信使。我正确地输入了代码,并且我对所有内容的作用有相当基本的了解。 尽管如此,我最终并没有得到相同的结果。代码如下: public class Server extends JFr
是否有更优雅的方式来完成我在下面所做的事情?也就是说,是否有比轮询和 hibernate 、轮询和 hibernate 等更优雅的方式来知道何时 Runnable.run()方法已通过 invokeL
我在使用 invokeLater 更新 JLabel 值时遇到问题。我在运行 invokeLater 的主函数之外有一个单独的方法,但是当我单击搜索按钮更新值时,它不会在同一个 gui 实例中更新。我
我使用推荐的代码启动我的交互式程序,它使用 Swing。 : public static void main(String[] args) { javax.swing.Swin
EventQueue javadoc 声明要求排队的事件按顺序和顺序分派(dispatch)。 与 EventQueue.invokeLater 一起排队的 Runnable 保证在后续用户事件(例如
有时我觉得使用 AsyncTask 对任务来说太过分了,我正在寻找类似的功能,如 Android 中的 SwingUtilities.invokeLater。因为我只想执行一行代码,没有必要为此创建一
我的问题与 SwingUtilities.invokeLater 有关。我应该什么时候使用它?每次需要更新 GUI 组件时都必须使用吗?它究竟是做什么的?是否有替代方案,因为它听起来不直观并且添加了看
我有一个问题,关于使用 SwingUtilities 的 invokeLater 方法的正确做法是什么。 因此,首先,我想确认我的理解是否正确。 据我所知,必须在 EDT 上更改 GUI,因为 Swi
我有一个线程使用 SwingUtilities.invokeLater 在我的 JFrame 上显示更新。线程的速度是可调的,当它设置为全速(更新之间没有 sleep )时,我的程序会严重减慢。我想问
我从来不理解SwingUtilities.invokeLater,这就是我一直避免使用它直到现在的原因。但是确保 Swing Thread 安全非常重要。好吧,请原谅,因为这是我第一次这样做。我试图在
这个问题已经有答案了: What does SwingUtilities.invokeLater do? [duplicate] (5 个回答) SwingUtilities.invokeLater
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我正在使用 invokeLater() 在 JEditPane 中加载 html 页面,该 JEditPane 位于 JPanel 中,而 JPanel 位于 JTabbedPane 中。 我的所有方
I had a problem earlier我试图将对象添加到 Canvas 中,但 SwingUtilities.invokeLater 尚未真正完成其工作。我确实需要能够可靠地向此 JPanel
我正在尝试使用多线程模拟一个简单的恒温器。恒温器应提高温度以达到用户请求的值,即下面代码中的“最大值”。我有两个线程,一个负责提高温度,另一个负责降低温度。但减少的条件是必须在关气时才运行。但我在实现
我是一名优秀的程序员,十分优秀!