How do I show JFrame before the JLabel value is calculated
I am making a Java Desktop Application using Net开发者_开发百科beans. I am new to Desktop Applications and I'm not all that great with Java ether.
I have a JLabel with a count value that takes a minute or two to calculate. The value is the total files on the computer.
I have a Master class which has one method for the counting of the files and another one that sets the JFrame to visible and passed the count value to the JFrame class which is then assigned to the JLabel.
This is what I want:
- Set JFrame to visible right away without waiting for count calculations.
- Show Count value so far and update every second until the count calculations are done.
What code would I use to do this?
label.setText();
Read the section from the Swing tutorial on Concurrency. You can use the SwingWorker to execute your long running task in the background. Then you periodically publish values and and update the GUI using the setText() method.
精彩评论