Swing - 更新标签 [英] Swing - Update Label

查看:112
本文介绍了Swing - 更新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个邮件标签和一个提交按钮。



当按下按钮时,我想设置消息为空,并且任务完成后,我要将消息设置为完成。

  private void submitActionPerformed .awt.event.ActionEvent evt){
message =;
updateMessageLabel();

doTheTask();

/ *此更新适用于完成后的标签* /
message =Complete;
}

是否可以在

解决方案

是的,您可以使用 SwingWorker 线程执行所有pre submitActionPerformed() ,在 currentThread execute()方法并调用 doTheTask()作为后台作业使用worker Thread



建议您阅读本文档以参考 SwingWorker线程


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?

解决方案

Yes you can do this using SwingWorker thread, do all the pre submitActionPerformed() activities like updating the label, in the execute() method of the currentThread and call doTheTask() as a background job using worker Thread.

I suggest you to go through this documentation for reference about SwingWorker Thread

这篇关于Swing - 更新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆