I haven’t used java in awhile and I am trying to do something like this in one main class:
// do stuff
this.label.setText("Status: IDLE");
// do things
this.label.setText("Status: LOADING..."); // set to loading right before file read
// read and parse huge file
this.label.setText("Status: DONE");
I want the label to show ‘loading…’ as the large file read is being executed but the label never freezes (as the job is being ran). How can I force the label to change during read? Do I need to use separate class/thread? Thanks in advance for your help.
Yes, you are right. The label and the class that is changing it’s value should be in different threads.
Have a look at SwingUtilities invokeLater:
You can create a thread this way showed above.