Updating Swing Window While Doing Work With Threads
From: Hal Vaughan (hal_at_thresholddigital.com)
Date: 09/30/04
- Next message: _Mario_: "Re: Cloudscape-derby admin tool"
- Previous message: Mike B: "Re: Creating a .jar package file"
- Next in thread: Paul Lutus: "Re: Updating Swing Window While Doing Work With Threads"
- Reply: Paul Lutus: "Re: Updating Swing Window While Doing Work With Threads"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Sep 2004 00:31:56 -0400
I've been having problems with different versions of this situation. This
is the newest variation. I know I need to use Thread to create a parallel
thread so when I want to update Swing components AND do something else, I
have to put the other stuff in a thread. But that isn't enough. In this
case, I want to wait 5 seconds, get updated information from the disk, then
update the JLabels on a display. When done, I loop and do it again. I'm
trying this with an "invokeLater()" to allow updates to continue, but it
doesn't work.
Maybe I misunderstand "invokeLater()", but I thought the idea was it would
wait until any Swing component updates were done, THEN run the thread. It
doesn't seem to in this case. I open the window (which should involved
drawing all the components), and call this loop. Not only is nothing
updated, but the window elements never get drawn.
Isn't there SOME way to slip in a command that says something like "Stop
here, wait for all components to be updated, THEN go on"? I have other
programs where I have to get info out of a thread and into JComponents, but
it seems impossible for any Swing updating code to live harmoniously with a
thread where the updates and the thread need to remain synchronous.
I've included the problem code below.
Thanks!
Hal
public void loop() {
Thread tRunner = new Thread() {
public void run() {
try {Thread.sleep(5000);} catch (Exception e) {}
}
};
while (true) {
SwingUtilities.invokeLater(tRunner);
update();
//Variables don't effect overall question -- just way to exit loop
if (iMerge == 0 && iOther == 0 && iPrint == 0 && bQuitFlag) {break;}
};
if (bQuitFlag) {System.exit(0);}
return;
}
- Next message: _Mario_: "Re: Cloudscape-derby admin tool"
- Previous message: Mike B: "Re: Creating a .jar package file"
- Next in thread: Paul Lutus: "Re: Updating Swing Window While Doing Work With Threads"
- Reply: Paul Lutus: "Re: Updating Swing Window While Doing Work With Threads"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|