There are a whole raft of problems here:
You are doing Swing GUI updates from not on the EDT Thread.
Your isvisible variable is not volatile so changes made from one thread may not be seen from another.
While(true) sleep in a thread is generally bad design.
You should use a SwingTimer
here with a schedule to call back every X to do the update. When you need to stop the update just cancel the SwingTimer
and hide the control. The hide needs to be done from the EDT too though so you may need to do SwingUtilities.invokeLater
.
There may be more too but that's what I've seen so far.