Results 1 to 3 of 3

Thread: JFileChooser

  1. #1
    javabarn is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default JFileChooser

    I am using JFileChooser to open data files I have created but am unable to find a simple explanation as to how to filter them to a specific file extension type. Can anyone help please?

    [code]
    {File f = new File(thingsName+".zzz");// set to existing file
    chooser.setFileSelectionMode(JFileChooser.FILES_ON LY);
    chooser.setSelectedFile(f);
    int returnVal=chooser.showOpenDialog(null);
    File curFile=new File("");
    if (returnVal == JFileChooser.APPROVE_OPTION)//file selected
    { curFile = chooser.getSelectedFile();
    System.out.println("File Type= "+curFile);}



    [\code]

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    6

  3. #3
    javabarn is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    After very confusing run round the various Sun samples and Definitions found this VERY simple example of how to implement a filter- so simple compared with all the others
    Java: javax.swing.filechooser.FileFilter

    Java Code:
    class SQLfilter extends javax.swing.filechooser.FileFilter {
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".sql");
        }
        
        public String getDescription() {
            return "SQL files";
        }
    }//______________
    
    
    chooser.setFileFilter(new SQLfilter());
    Last edited by javabarn; 07-12-2010 at 06:11 PM. Reason: quoted zzz not original sql as extension

Similar Threads

  1. jfilechooser
    By ranadav in forum AWT / Swing
    Replies: 7
    Last Post: 06-03-2010, 02:44 PM
  2. Jfilechooser
    By greatmajestics in forum Java 2D
    Replies: 5
    Last Post: 03-30-2010, 06:13 PM
  3. help with JFileChooser
    By morgatron in forum New To Java
    Replies: 1
    Last Post: 01-08-2010, 09:00 AM
  4. JfileChooser Help
    By simmi in forum AWT / Swing
    Replies: 9
    Last Post: 08-04-2009, 02:24 AM
  5. how to use JFileChooser
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •