Example analysis of Jfilechooser usage of Java swing component

This article describes the usage of Jfilechooser, a java swing component. Share with you for your reference, as follows:

Jfilechooser file selector is a frequently used control in swing. Its usage mainly includes the following parameters:

1. Current path. That is, the path where it is opened for the first time. Many software like to set it as the desktop.

2. File filter. By setting the file filter, only certain types of files are visible, such as text, audio, etc.

3. Select the mode. There are three cases: file only, directory only, file or directory.

4. Allow multiple selections.

Of course, Jfilechooser has more than the above four parameters. It also has many advanced options. For example, you can customize the display icon of the file. Because it is not often used, it will not be introduced here.

There are two points to note:

1. Filenameextensionfilter is recommended for file filter. It is a subclass of filefilter and implements the filter in a very convenient way. See code for usage.

2. Getselectedfiles() method, which is valid only when ismultiselectionenable() method returns true. That is, if you do not allow multiple selections, you can only use the getselectedfile () method, otherwise you can only get an empty file list.

Here is a demo to show its basic usage.

The operation effect is as follows:

More readers interested in Java related content can view the special topics of this site: Java data structure and algorithm tutorial, summary of Java character and string operation skills, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>