mukta
mukta

Reputation:

Remove allfile option in JFileChosser Java

I'm using swings JFileChooser in program. I want it to filter files with .txt-extension and it is showing allfiles option also in window. I want to remove allfiles option, how can I do that?

This is my code:

fc1 = new JFileChooser();

fc1.setMultiSelectionEnabled(true); // Allow for multiple selections
fc1.setCurrentDirectory(new File("C:\\"));
fc1.setFileFilter(new FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".fls")
                    || f.isDirectory();
        }

        public String getDescription() {
            // TODO Auto-generated method stub
            return "*.fls";
        }
    });

Upvotes: 0

Views: 135

Answers (1)

aberrant80
aberrant80

Reputation: 13016

Well, just by reading the javadoc, I can see that there's a method called setAcceptAllFileFilterUsed(boolean). Did you try that? It sounds like it's doing what you want.

Upvotes: 2

Related Questions