• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton Got Hanged

 
ranua agarwal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
ranua agarwal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter for the quick response.
Well, i am using Java6.
Now i am looking into the SwingWorker class.
 
ranua agarwal
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Taucher wrote:Are you aware that event handling happens in EDT?

Nope Peter. Never heared about EDT.
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Peter for suggestion.
Will follow it.
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic