Question

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.

Was it helpful?

Solution

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() }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top