// save a file using JFileChooser

import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
...
// ask user where to save.
// persisted in registry directory last used
Preferences userPrefs = Preferences.userRoot().node( "/com/mindprod/mypackage" );

File suggestedFile = new File ( userPrefs.get( "SAVEDIR", "C:" ), saveName );

JFileChooser fc = new JFileChooser();
fc.setSelectedFile( suggestedFile );

// filter out all but JPG files from view, you need
// a javax.swing.filechooser.FileFilter
// NOT a java.io.FilenameFilter;
fc.addChoosableFileFilter( new JpgFileFilter() );
// In a simple case like this you could have used
// javax.swing.filechooser.FileNameExtensionFilter
// instead of rolling your own custom FileFilter.

int result = fc.showSaveDialog( this );
switch ( result )
   {
   case JFileChooser.APPROVE_OPTION:
      File file = fc.getSelectedFile();
      ...
      // save using file.
      ...

      // save same directory for next time.
      // persisted in registry, directory last used
      userPrefs.put( "SAVEDIR",  fc.getCurrentDirectory().getAbsolutePath() );
      break;
   case JFileChooser.CANCEL_OPTION:
   case JFileChooser.ERROR_OPTION:
      break;
   default:
   }

----------------------------------------------------------------------------------------

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 * Creates a file filter that accepts only *.jpg files.
 *
 * @author Roedy Green
 * @version 1.0
 * @since 2004-05-06
 */

public class JpgFileFilter extends javax.swing.filechooser.FileFilter
   {

   /**
    * Creates a file filter that accepts only *.jpg files.
    *
    */
   public JpgFileFilter()
      {
      }

   /**
    * Return true if this file should be shown in the directory pane,
    * false if it shouldn't.
    *
    * accepts directories and.jpg files.
    *
    * @see FileFilter#accepts
    */
   public boolean accept( File f )
      {
      if ( f != null )
         {
         if ( f.isDirectory() )
            {
            return true;
            }
         String name = f.getName().toLowerCase();
         return name.endsWith( ".jpg" );
         }
      else
         {
         return false;
         }
      }

   /**
   * Returns the human readable description of this filter.
   * @see setDescription
   * @see setExtensionListInDescription
   * @see isExtensionListInDescription
   * @see FileFilter#getDescription
   */
   public String getDescription()
      {
      return "*.jpg image files";
      }
   }