Search This Blog

Showing posts with label filenameextensionfilter. Show all posts
Showing posts with label filenameextensionfilter. Show all posts

How to Filter Filetypes using File Extensions in JFileChooser - Java File Chooser

how to filter files in Jfilechooser by file types or file formats using extensions in filename java codefile name file type filefilter file filter filtering files
Screenshot of following example java program
In java, to browse files or folders from the file system, we use the JFileChooser class. You can use  the JFileChooser object in two modes, save mode or open mode. Here we discuss about filtering file type by file extensions for opening the file. By default, the JFileChooser object will have an AcceptAllFileFilter. This file filter will allow the user to select file of any file type. The file filter will display text All files. If you want to restrict the file chooser to open only one type of file, you should first remove the AcceptAllFileFilter. To do this, call the following method:

myfilechooser.removeChoosableFileFilter(createoropenchooser.getAcceptAllFileFilter());