Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

button gets locked until process completes

Posted on 2003-03-24
9
Medium Priority
?
170 Views
Last Modified: 2010-03-31
I am trying to develop a jFrame application but when i click on the button to do some task the button gets stuck with the container and container doesnt provide to do any other task, is there any way out to release the lock and let the process run on the back ground.
0
Comment
Question by:kausiksarkar
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 8200885
What is your actionPerformed () method??

Mayank.
0
 
LVL 92

Expert Comment

by:objects
ID: 8200914
You need to do your processing in a new thread.
Swing runs in a single thread so if you block that thread gui updating is blocked.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 8200919
public void actionPerformed(ActionEvent e)
{
   new Thread(new Runnable() {
      public void run() { doLongProcessing(); }}).start();
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Expert Comment

by:yongsing
ID: 8200925
Most likely you are performing the task in the event dispatching thread. That's why the event dispatching thread doesn't get the chance to repaint the button. What you can do is to create a new thread to perform the task.
0
 
LVL 3

Expert Comment

by:zero303
ID: 8201076
This happened to me when i'd accidently done the old inifinite loop lol, it was my first ever Java GUI and like you said the button freezes... It was just waiting to finish the never-ending loop!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8201096
Please post your actionPerformed () method so that we can see why its freezing.

Mayank.
0
 

Author Comment

by:kausiksarkar
ID: 8201511
Thanks objects u r really great it works and works very well i have never been any idea like this. Thanks a lot.
0
 

Author Comment

by:kausiksarkar
ID: 8201514
Thanks for this great solution i really shocked to see it works. Thanks a lot man.
0
 
LVL 92

Expert Comment

by:objects
ID: 8206382
No worries, glad it did the trick for you :-)
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question