Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 FileFilter issues. 1

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
0
0
GB
I have a GUI application that includes a save file JFileChooser function. I have included a default save file name but everytime I click on a different directory to save the file in, the name in the save as text field dissapears (it doesnt do this in eclispe) forcing the user to type in a new file name (very annoying!).

...
JFileChooser fc = new JFileChooser();
...
File saveFile = new File("saveFile.html");
...
fc.serSelectedFile(saveFile);


Also I have included a filter to save the file as a .html file but if the user removes the extension from the "save as" name, the extention does not get added. E.g. "file.html" gets changed to "file" with a filter of *.html gets saved as "file".

...
fc.setFileFilter(new FileFilter() {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
return f.getName().toLowerCase().endsWith(".html");
}
public String getDescription() {
return "*.html";
}
});

fc.setAcceptAllFileFilterUsed(false);
...

Any thoughts or words of wisdomk would be greatly appreciated. Many thanks :)



 
Humm, looks like JFileChooser is in the wave

No idea about the first one, but about the second one and AFAIK, the FileFilter just states which files will be shown in the view.

Btw, has been resolved the bug that didn't show a warning before overwriting a file?

Cheers,
Dian
 
No error is shown if you are over writing a file, I thought that was odd!!

Is there any way to ensure that the extension gets appended should it be removed?

Thanks for the help it is greatly appreciated :)

 
It doesn't look like there is. You may have to examine the naming of the File returned from JFileChooser and reapply the desired extension if it is missing.

Tim
 
Same goes for the "overwrite bug." On saves, check to see if the file exists, put up a warning and open the file chooser again if the user so desires.
 
That sound logical and something I can do!

I really appreciate the help Miros, timw and Dian.

Cheers :)
 
The overwrite bug has been fixed on later version, btw.

Cheers,
Dian
 
Thanks Diancecht! I guess I need to upgrade my Java then...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top