进度条,用于加载另一个JFrame类 [英] Progress bar for loading out another JFrame class

查看:316
本文介绍了进度条,用于加载另一个JFrame类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个JFrame:NewJFrameNewJFrame1. NewJFrame有一个进度条和一个按钮.该按钮用于调用NewJFrame1.单击该按钮时,它将触发进度条运行,直到弹出NewJFrame1为止.但是,我如何利用swing工作者并使进度运行,直到NewJFrame1实际上竞争性地加载了其所有组件?

I have 2 JFrame: NewJFrame and NewJFrame1. NewJFrame has a progress bar and a button. the button is used to call up NewJFrame1. When the button is clicked it should trigger the progress bar to run until NewJFrame1 pop up. However, how do I make use of the swing worker and let the progress to run until NewJFrame1 actually competely loaded all of its component?

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    SwingUtilities.invokeLater(new Runnable() {
        int i = 0;
        public void run() {
           jProgressBar1.setValue(i++);
           new NewJFrame1().setVisible(true);
        }
    });
} 

推荐答案

让您的此处所示,以及PropertyChangeListener,如此处所示.当doInBackground()调用setProgress()时,侦听器将看到事件.

Let your top-level container have a SwingWorker that loads it's content, as shown here, and a PropertyChangeListener, as shown here. When doInBackground() calls setProgress(), the listener will see the event.

附录:我们如何知道GUI完全加载还剩下多少时间? …在示例中,进度条以随机数作为模拟等待时间运行..

正确;模拟的延迟表示您的加载粒度.显示加载的总字节数的比例将是理想的,但是您可能必须适应较粗的频率.请注意,可以在任何组件正在监听的之前在后台构造模型. GUI组件应仅在EDT上构造和操作,可能在工作人员的process()实现中.

Correct; the simulated latency represents the granularity of your loading. Displaying the fraction of total bytes loaded would be ideal, but you may have to settle for a coarser frequency. Note that models may be constructed in the background, before any components are listening. GUI components should be constructed and manipulated only on the EDT, possibly in the worker's process() implementation.

这篇关于进度条,用于加载另一个JFrame类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆