• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help: JFileChooser displaying previous selection  RSS feed

 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a static JFileChooser object avaible in my application. I went with a static object so that when the "Open File" dialog is shown, it opens to the last directory navigated by the user.

This works great. The only problem is that when it displays any file(s) previously selected are shown as selected. Is this a bug? Is there any way around this?

Thanks.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try

as you close the dialog to reset the JFileChooser.
 
Rich Smyth
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
File f = new File("");
File [] files = {f};
myFileChooser.setSelectedFile(f);
myFileChooser.setSelectedFiles(files);

is one way to reset the selected file(s). When I had the same problem setting to null did not help.


Rich
[ July 20, 2004: Message edited by: Rich Smyth ]
 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Your suggestion worked great.
Steve

Originally posted by Rich Smyth:
File f = new File("");
File [] files = {f};
myFileChooser.setSelectedFile(f);
myFileChooser.setSelectedFiles(files);

is one way to reset the selected file(s). When I had the same problem setting to null did not help.


Rich

[ July 20, 2004: Message edited by: Rich Smyth ]

[ July 21, 2004: Message edited by: S Saunders ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!