Swing - 更新标签
我有一个消息标签和一个提交按钮。提交按钮将被按下多次,每次按下的操作最多可能需要一分钟。
当按下按钮时,我想将消息设置为空,任务完成后,我想将消息设置为“完成”。
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
message = "";
updateMessageLabel();
doTheTask();
/* this update is apply to the label after completion */
message = "Complete";
}
是否可以在运行 submitActionPerformed()
方法之前(或在方法中)但单击按钮之后更新该消息标签?
I have a message label and a submit button. The submit button will be pressed multiple times, and the action for the each press can take up to a minute.
When the button is pressed, I want to set the message to empty, and after the task is complete, I want to set the message to "Complete".
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
message = "";
updateMessageLabel();
doTheTask();
/* this update is apply to the label after completion */
message = "Complete";
}
Is it possible to update that message label before the submitActionPerformed()
method is run (or in the method), but after the the button is clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管 Swing 并发教程 已经包含了一些非常好的示例如何处理 Swing 中的并发性,请在下面找到一个示例,其中
SwingWorker
更新有一个标签,它获取更新一次
SwingWorker
已完成Although the Swing concurrency tutorial already contains some very good samples on how to deal with concurrency in Swing, find below an example which
SwingWorker
has a label, which gets updated once the
SwingWorker
is finished是的,您可以使用
SwingWorker
线程执行此操作,在execute()
方法中执行所有预submitActionPerformed()
活动,例如更新标签currentThread
并使用工作线程Thread
调用doTheTask()
作为后台作业。我建议您阅读此文档以参考有关 SwingWorker 线程
Yes you can do this using
SwingWorker
thread, do all the presubmitActionPerformed()
activities like updating the label, in theexecute()
method of thecurrentThread
and calldoTheTask()
as a background job using workerThread
.I suggest you to go through this documentation for reference about SwingWorker Thread