Results 1 to 3 of 3

Thread: JFileChooser Hide file type

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    JFileChooser Hide file type

    How can I hide certain files in a JFileChooser control? This is what Im using so far but I can still see files I dont want to see.

    Code:
         JFrame frame = new JFrame();
              
              
                String filename = "Desktop";
        JFileChooser fc = new JFileChooser(new File(filename));
        
        
        
           fc.setFileFilter(new FileFilter() {
       public String getDescription() { return "CSV files"; }
       public boolean accept(File f) {
          if(f.isDirectory()) return true;
          if(f.getName().endsWith(".csv")) return true;
          return false;
        }
       });
       
    
        
        // Show save dialog; this method does not return until the dialog is closed
        fc.showSaveDialog(frame);
       cFile = fc.getSelectedFile();

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: JFileChooser Hide file type

    Can you explain a little more? I don't know what files you don't want to see and what it's showing up.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: JFileChooser Hide file type

    I tried this code:
    Code:
                public void actionPerformed(ActionEvent e)
                {
                    JFileChooser chooser=new JFileChooser();
                    chooser.addChoosableFileFilter(new FileFilter(){
    
                        public boolean accept(File f)
                        {
                            if(f.isDirectory())return true;
                            else if(f.getName().endsWith(".csv"))return true;
                            else return false;
                        }
    
                        public String getDescription()
                        {
                            return "Comma separated file";
                        }
                    });
                    if(chooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
                    {
                        //Do your things
                    }
                }
    and it works
    Last edited by ComputerJy; Jul 13th, 2007 at 06:19 AM.
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width