Hey all, for quite some time I've been working on an inventory management program for work, and I'm having a bit of an issue with the rendering of a JFrame notification window, I'll do my best to explain below (including screenshots).

So my program works with a remote FTP server to store information, and because of the immense amount of data being transferred over the network, there is a few second delay (program locks up basically) when performing operations that involved data transfer. What I have decided to do, is have a pretty looking JFrame pop up informing the user of network usage when these actions start up, and then hide when the code is done (it should look like this screenshot). The problem is the window fails to render when it is made visible during these events - when the file transfers occur right after the .setVisible(true); call. (Which looks like this screenshot) If the JFrame's .setVisible(true); call is made with the "server" object file transfer call's commented, everything works fine (as seen in the first listed screenshot).

This leads me to believe that the Thread is getting locked up from the file transfer before it's done rendering the swing elements (I've done this with a basic window as well - not all jazzed up like you've seen in the screenshots so I know it has nothing to do with the visual styling itself). I've tried making Thread.yield(); calls and Thread.sleep(1000); to give it time to render but that doesn't seem to help (probably because the JFrame call is on the same Thread). Any thoughts on what I should do to give it just a tiny bit more time to render or any other ideas - possibly put the file transfers on a different Thread - haven't tried this before, how would I do it?

Any help is appreciated!

7 Years
Discussion Span
Last Post by JamesCherrill

Sorry to double post but I had an idea which I thought I'd run by the folks that stumble onto this thread (the new reply kinda separates this idea from the general overview in the original post).

While it would be a fairly lame fix, I suppose it would be possible to make the data transfer call be an AbstractAction called by a timer that would get started when the usual data transfer gets started. Meaning the Thread would continue running as normal but it would wait - half a second or a second - until the frame has been rendered. I'm not a big fan of this idea mainly because it relies on time which won't be constant for different hardware configurations....figured I'd toss the idea out there, but I'd prefer to hear from someone who has a more concrete fix to my problem.

Thanks for your time :)


Executing a long-running process in the Swing thread is a big no-no, for exactly the reasons you have discovered - ie the whole GUI hangs up while the process executes. Your only solution is to run the FTP process in a separate thread. Just place the call for your FTP in a run() method, and start a new Thread with it. You'll find a zillion web sites with examples, but if you get stuck I can give you more details.


Ah thanks, looking through the javadocs about the Thread object right now - pretty sure this will fix it straight up. The only concerns I've had in doing this is having the GUI move to a new stage to quickly, but I think I know how I'll combat any notification issues. Will let you know how it all turns out.

Thanks again.


Yes, SwingWorker is great - does exactly what you need, but it's new to Java 6 (JDK 1.6) so may not be on all systems just yet.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.