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
SwingWorkerthread, do all the presubmitActionPerformed()activities like updating the label, in theexecute()method of thecurrentThreadand calldoTheTask()as a background job using workerThread.I suggest you to go through this documentation for reference about SwingWorker Thread