문제

I want to change two progressBar immediately. but I can't.

what I'm saying is..

nextButton.addMouseListener(new java.awt.event.MouseAdapter() {     
    public void mouseClicked(java.awt.event.MouseEvent evt) {
        WorkProgressBar.setVisible(true);
        FileProgressBar.setVisible(false);

        AND SO ON(about 2 secs.)

        WorkProgressBar.setVisible(false);
        FileProgressBar.setVisible(true);
    }
}

that code takes about 2 or more seconds.

but what I can see is just blink of ProgressBar.

so I searched a lot of inform.

I used thread, swingworker, swingutilities(invokelater)

but I can't solved.

how can I solve this. please help me.

도움이 되었습니까?

해결책

You probably want to assign the tasks done in those 2 seconds to worker threads. Lets say you wanted to A.) decrement one progress bar and B.) increase another progress bar.

You'd assign one thread to do A.) by implementing its run method to do just this. And then the other thread will do the work on B.)

Now in the meantime, you want your main thread (which is what assigns these 2 threads to start doing their work) to wait until your worker threads are done. So after doing thread1.start() and thread2.start(), you'd wait for them to finish by doing a join, like this:

try {
    thread1.join();
    thread2.join();
} catch (Exception e) { e.printStackTrace() }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top