Add a PNG Files filter and select it by default

This commit is contained in:
Sam Harwell 2013-03-07 15:21:49 -06:00
parent 5fdb01499d
commit 7d52fb7ecd
1 changed files with 19 additions and 0 deletions

View File

@ -369,6 +369,25 @@ public class TreeViewer extends JComponent {
JFileChooser fileChooser = new JFileChooserConfirmOverwrite();
fileChooser.setCurrentDirectory(suggestedFile.getParentFile());
fileChooser.setSelectedFile(suggestedFile);
FileFilter pngFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
if (pathname.isFile()) {
return pathname.getName().toLowerCase().endsWith(".png");
}
return true;
}
@Override
public String getDescription() {
return "PNG Files (*.png)";
}
};
fileChooser.addChoosableFileFilter(pngFilter);
fileChooser.setFileFilter(pngFilter);
int returnValue = fileChooser.showSaveDialog(dialog);
if (returnValue == JFileChooser.APPROVE_OPTION) {