File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Creating a dialog in a listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Creating a dialog in a listener" Watch "Creating a dialog in a listener" New topic

Creating a dialog in a listener

Brian Flowers

Joined: Aug 23, 2009
Posts: 3
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.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10826

You might want to check out this article

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Brian Flowers

Joined: Aug 23, 2009
Posts: 3
Huh...I thought the actionListener already ran as a thread...guess I need to revisit some Java basics...

Anyway, that worked, thanks!
I agree. Here's the link:
subject: Creating a dialog in a listener
jQuery in Action, 3rd edition