• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

paust main thread for until finish work. Stop button.

 
sabari selvan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*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
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sabari Selvan, please BeForthrightWhenCrossPostingToOtherSites.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49808
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic