Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a dialog in a listener

 
Brian Flowers
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Brian Flowers
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Huh...I thought the actionListener already ran as a thread...guess I need to revisit some Java basics...

Anyway, that worked, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic