• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileDialog not working!!

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I am trying to use a java.awt.FileDialog to let the user save a file. But I cannot figure out how to receive the event when the user presses "Save" or "Cancel".

I tried registering a WindowListener to catch when the dialog closes, and then retrieve the file name. But it never calls the listener




When I run this program and press the "test" button, it pops open the save dialog. It calls the windowOpened() callback.

But it never calls any of the callbacks after the user enters the filename and hits "save".

How do I get notified of this event???

Thanks
Geoffrey
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks like an 'in progress' bug (since Jan 97)

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4028889
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael, so this means FileDialog is pretty useless to me then!!

Is there any other way to get the filename when the user presses "Save"?

Geoffrey
[ January 24, 2007: Message edited by: Geoffrey Falk ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason you have to use awt and can't use Swing? Then you could use the JFileChooser. I've never had a problem with it.
[ January 24, 2007: Message edited by: Gregg Bolinger ]
 
Brian Cole
Author
Ranch Hand
Posts: 899
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with JFileChooser is that it has tended to track the native look-and-feel poorly. I try to use AWT FileDialog whenever I can, and fall back to JFileChooser when I have too, which unfortunately is fairly often. I wish that the powers that be would put some work into modernizing FileDialog.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite following what the listeners are supposed to do. That's not how FileDialog works. The call to setVisible will return when the user has dismissed the dialog, either by clicking Save or Cancel. Then you can call its getFile method - if that returns null, then it was Cancel, otherwise it returns the file name (and getDirectory the directory). Am I missing something?
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
I'm not quite following what the listeners are supposed to do. That's not how FileDialog works. The call to setVisible will return when the user has dismissed the dialog, either by clicking Save or Cancel. Then you can call its getFile method - if that returns null, then it was Cancel, otherwise it returns the file name (and getDirectory the directory). Am I missing something?


OK, you are partly right and I was partly wrong.

The call to setVisible(true) returns immediately. This was my mistake.

By using show() instead, it will block until the user is done.

By using the show() method I was able to get it working. I avoided it the first time because Eclipse says that this method is deprecated (?).

Geoffrey
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the FileDialog I get the same behavior from .setVisible(true) and .show() - both block until the user closes the dialog in some way...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic