| 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: 1808
|
|
|
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.
|
 |
 |
|
|
subject: JButton Got Hanged
|
|
|