Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using threads or there's another way?

 
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: 22542
109
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:
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!