• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Message doesnt display continuously

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm using the code bellow (written a couple of years ago) to display a message to a jLabel, for a few seconds
yet, the message does display but with "hicups", not permanently: for example - shows for 4 seconds, then disappears for a fraction of second, then resumes displaying...
i tried several combinations for sleep value and for var i, but the present combination looks like the best so far
is there something wrong with the code?

the code:
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swing isn't thread safe. You are not allowed to change swing components in any thread but the event dispatching thread.

Henry

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Any method call that affects the visualization in any way, should(must) be executed from the EDT.
In your case it's not.
The thing is, that you've just created a new worker/background thread on the EDT.
The same result would be achieved, if you'd comment the following lines: 3,4,21 & 22.

The "visual" call in your example is setText(...).
Put it on the EDT like:



Regards,
Rok
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this isnt the first time it happens: i rely on email notification and when i notice, several hours elapsed since first answer
anyway thank you both for your answers
using the (new) code bellow i dont perceive any irregularity in display
please fell free to comment what i wrote:
 
Marshal
Posts: 28295
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sort of thing is exactly what javax.swing.Timer is meant for. Try that instead.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for the idea!
i came up to the following code, but for somw reason, when i hover out of rhe button that triggers the method, the message vanishes... i kmow i have some code for hovering, but with the other method that didnt happen

please comment in case you find something wrong
 
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our GUI forum.
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post deleted. ;)
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to flash the text or what?


OR
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mikko: i'm trying not to flash
anyway, among others, i get an error message using your code in line 12, saying:

the method sleep(int) is undefined for the type new Runnable(){}

 
Rob Spoor
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a static method in Thread.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm feeling a bit embarrassed because i cant write it in order to compile:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
Syntax error on token ";", { expected after this token
Syntax error, insert "}" to complete ClassBody
Syntax error, insert ";" to complete BlockStatements

at util.Util.mostraMensagem(Util.java:92)

 
Rob Spoor
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're missing a }.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:You're missing a }.


yes, that's what the compiler says
but i just cant figure out where, because if i added it here, gives an error there, and viceversa, and so on - believe me i tried a lot indeed, wtill with no results
 
Rob Spoor
Sheriff
Posts: 22800
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 25 here ends the while loop, and line 26 ends the anonymous inner class. You don't close the run method.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the code below does compile and run, at last
thanks to everyone!
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic