paust main thread for until finish work. Stop button.
Joined: Oct 10, 2011
*What i want to do?*
I am developing swing based application.
whenever user click start button, it do some work and return the result to main panel. I should enable stop button for user.
Problem 1: whenever i click the button, it will start to run but the main panel is inaccessible. So i am not able to click the stop button.
Problem 2: I replaced the method with thread concept. Main and other thread works concurrently, so i am able to access the main panel now. That's nice.
Bad Thing is: The result statement in the main thread is executed before the other thread finish it's work. So it will display nothing as result.
What i can do? give me some suggestion.
Sorry i misplaced the thread . please move this thread to thread forum
Joined: Jun 09, 2003
>Bad Thing is: The result statement in the main thread is executed before the other thread finish it's work. So it will display nothing as result.
execute the result statement at the end of the 'other thread', via SwingUtilities.invokeLater(..)
Rob has already told you in your other thread to use SwingWorker. Obviously you must not pause a thread. What is happening is that the thread is busy until your task is completed. You have also probably been told, all Swing components must be accessed from the same thread, called the Event Dispatch Thread.