In my application I have a JTree that I am going to update every xxx minutes. So I made this class:
Now I have a class that extends JPanel and in that class I build my tree. After I build my tree I then want to go ahead and start the Runnable class so that the tree will update every xxx minutes. So I do this:
I have also tried
The problem is that this Runnable starts running, but I never get returned to the GUI. Everything in the GUI just hangs while the Thread runs. Any ideas?
BTW - This is a JApplet in case that makes a difference.
You shold not use invokelater().Since invokelater() executes the thread in the event dispatched thread and as your thread runs in an infinite loop it will never end and your application will hang. Why dont you run it as a seperate thread alltogether. new Thread(Runable/*your Runnable class*/).start();
it is right to do the updating in the AWT-main-thread. so I'd suppose it's safer to do this:
when you catch the interrupted exception you should call "Thread.currentThread().interrupt()" - unless the current thread is the AWT-main-thread, of course. otherwise the thread does not die. this polling thread will most probably never be interrupted, but for data retrieval in a gui, it is important. see this very good article on stopping threads: http://www.javaspecialists.co.za/archive/Issue056.html Chantal [ November 25, 2002: Message edited by: Chantal Ackermann ]