Forums Register Login

Creating a dialog in a listener

+Pie Number of slices to send: Send
Ok, so I'm trying to have an actionListener that, when triggered, creates a dialog with a progress bar. Seems like this would be a pretty common thing to do - you hit a button, a popup comes up saying 'Loading...' or whatever while it's processing something. But here's the problem - the progress bar never appears. The dialog comes up, but it's empty. I've spent a couple hours looking at this and have figured out that the problem definitely arises from putting the code inside the actionListener. I'm assuming it has something to do it being run as a separate thread, but I'm not sure what to do about it...

I've diluted the code I'm working on down and posted it below...and it's basically is a heavily modified version of this example.


Also probably worth noting that if I comment out dlg.setVisible(false) [line 39], the progress bar will appear after the rest of the listener completes, but at that point you can't do anything since it's a modal dialog (as it should be).

Anyone have any ideas how to make this work, or a better way of doing this? I mean I suppose I could have the dialog be static class member and just turn it on and off as needed, but that seems a strange way of doing it and not quite ideal for my project.
+Pie Number of slices to send: Send
You might want to check out this article
http://faq.javaranch.com/java/JProgressBarDoesntUpdate
+Pie Number of slices to send: Send
Huh...I thought the actionListener already ran as a thread...guess I need to revisit some Java basics...

Anyway, that worked, thanks!
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1251 times.
Similar Threads
JProgressBar
gui and thread
JProgressBar - Please Help
SIMPLE updating dialog!!!
Swing worker thread
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:54:47.