aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes paust main thread for until finish work. Stop button. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "paust main thread for until finish work. Stop button. " Watch "paust main thread for until finish work. Stop button. " New topic
Author

paust main thread for until finish work. Stop button.

sabari selvan
Greenhorn

Joined: Oct 10, 2011
Posts: 3
*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.

*The Problem:*
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.


Update:
Sorry i misplaced the thread . please move this thread to thread forum

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
>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(..)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

There is a link to the Swing concurrency tutorial posted on the OP's crosspost here: https://forums.oracle.com/forums/thread.jspa?threadID=2296973&tstart=0.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

Sabari Selvan, please BeForthrightWhenCrossPostingToOtherSites.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Welcome to the Ranch

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: paust main thread for until finish work. Stop button.