Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using threads or there's another way?  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a swing standalone app i want a message to appear for a few seconds confirming user did deleted something
i'm using this code:

is there a better/smoother way of doing this?

TiA
 
Henry Wong
author
Sheriff
Posts: 22833
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, once your swing application has been displayed, you are not allowed to access any of the components from anything that is not the event dispatching thread. With the exception of a few methods, like repaint(), it is not thread safe to do so.

Having a separate thread to handle the timing for changing the visibility is fine, but it is not allowed to directly manipulate the component. Take a look at the invokeLater() method of the SwingUtilities to dispatch that task back to the event dispatching thread.

Henry
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm not sure if i got it right:
my main:

my refactored code:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!