bobrivers2003
Technical User
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
...
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