开发者

How do I show JFrame before the JLabel value is calculated

开发者 https://www.devze.com 2023-03-12 06:21 出处:网络
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 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:

  1. Set JFrame to visible right away without waiting for count calculations.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号