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