0

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

Thanks.

3
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by peter_budo
0

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

Although that's just me thinking out aloud.

0

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.

0

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.

0

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.

0

http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter09/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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.