This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JButton Got Hanged Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton Got Hanged" Watch "JButton Got Hanged" New topic
Author

JButton Got Hanged

ranua agarwal
Greenhorn

Joined: Mar 31, 2010
Posts: 25
Hi,

Created a Bar chart for showing JVM memory status.
Toatal 30 JVM are running.
I am using JButton to refresh the bar chart to show current value.

Problem: When button pressed, all the frame got hanged until referesh button got released.

Is there any to come over this problem?

Thanks,
Ranu.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
Are you aware that event handling happens in EDT? Therefore you shouldn't process logical or long-running tasks there. All other events (like repaints for instance) can only happen, after your task is finished.

To handle such things comfortably, there's a class called SwingWorker, that can be used. Look here:
http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html

If you're constricted to older java versions (< 6) maybe you could use http://foxtrot.sourceforge.net/


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
ranua agarwal
Greenhorn

Joined: Mar 31, 2010
Posts: 25
Thanks Peter for the quick response.
Well, i am using Java6.
Now i am looking into the SwingWorker class.
ranua agarwal
Greenhorn

Joined: Mar 31, 2010
Posts: 25
Peter Taucher wrote:Are you aware that event handling happens in EDT?

Nope Peter. Never heared about EDT.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
If you never heard about 'Swing components should be accessed on the Event Dispatch Thread (EDT) only.', that would be bad for a java/swing programmer. I can remember my first prototype in Java when the managing director simply said 'You there, learn java and implement this...' so many things I didn't know then ; - )
ranua agarwal
Greenhorn

Joined: Mar 31, 2010
Posts: 25
Thanks a lot Peter for suggestion.
Will follow it.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2154
    
    7
Read the section from the Swing tutorial on Concurrency to understand how Swings Single Thread rule applies to this problem and for a working example of a SwingWorker.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JButton Got Hanged
 
Similar Threads
Problem with the JButton.
Java API chart for Swing
polymorphism
setText not updating promptly
Draw a chart by using jsp/java code