944,073 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3464
  • Java RSS
Mar 24th, 2007
0

JFilerChooser default filefilter

Expand Post »
Hi, does anyone know how to set a JFileChoosers default filter back to accept all files after custom filters have been added?

Thanks.
Similar Threads
Reputation Points: 27
Solved Threads: 14
Junior Poster
Cerberus is offline Offline
162 posts
since Sep 2006
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

Surely it would be something on the lines of changing the *.txt filter back to "*."

Although that's just me thinking out aloud.
Last edited by iamthwee; Mar 24th, 2007 at 12:15 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

JFileChooser has a setFileFilter(FileFilter filter) method. I could call this by putting any of my custom filters in but i don't have an identifier for the default one. So basically i'm just wonding what the default identifier is.
Reputation Points: 27
Solved Threads: 14
Junior Poster
Cerberus is offline Offline
162 posts
since Sep 2006
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

Well surely the default filter must be *.*.

Which I would imagine was derived from a regular expression? But I don't have my java compiler at hand to test that. And the API for JFilterChooser may not include that.
Last edited by iamthwee; Mar 24th, 2007 at 12:52 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

but the setFileFilter method requires a FileFilter identifier not a String.

for example:

ExtensionFileFilter filter = new ExtensionFileFilter(text, "*.txt");
fileChooser.addChooseableFileFilter(filter);
chooser.setFileFilter(filter);

perhaps i'm misunderstanding.
Reputation Points: 27
Solved Threads: 14
Junior Poster
Cerberus is offline Offline
162 posts
since Sep 2006
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

http://www.particle.kth.se/~lindsey/...9/chooser.html

import javax.swing.*;
import java.io.*;

/** Filter to work with JFileChooser to select java file types. **/
public class JavaFilter extends javax.swing.filechooser.FileFilter
{
  public boolean accept (File f) {
    return f.getName ().toLowerCase ().endsWith ("*.*")
          || f.isDirectory ();
  }
  
  public String getDescription () {
    return "Java files (*.*)";
  }
} // class JavaFilter

Perhaps? Untested. Although I'd imagine it to be something along those lines?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

Ok thanks i'll take a look at the example.
Reputation Points: 27
Solved Threads: 14
Junior Poster
Cerberus is offline Offline
162 posts
since Sep 2006
Mar 24th, 2007
0

Re: JFilerChooser default filefilter

Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JNDI/JDBC lookup problem with Sun Java Application Server 8.2
Next Thread in Java Forum Timeline: help plss..emergency.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC