0

我有一个搜索一些文件的按钮,所以我试图在带有百分比数字的进度条中显示此任务的进度。我正在使用另一个线程来执行这个任务,但它需要很长时间,所以我想在进度条中显示它。

button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Runnable r = new Runnable() {

                public void run() {
                    //Process to search for files
                }
            };
            Thread t = new Thread(r);
            t.start();
        }
    });

请帮助我,我没有使用 JProgressBar 的经验。

4

1 回答 1

2

在阅读了一些使进度条工作的教程之后,我实现了下一个带有不确定进度条的解决方案:

button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Runnable r = new Runnable() {

                public void run() {
                        progressBar.setIndeterminate(true);
                        progressBar.setVisible(true);
                        progressBar.setStringPainted(true);
                        progressBar.setString("Searching..");

                    //Process to search for files

                        progressBar.setIndeterminate(false);
                        progressBar.setString("Completed Search");

                }
            };
            Thread t = new Thread(r);
            t.start();
        }
    });
于 2013-03-13T12:27:31.930 回答