Hi im working in a java project and i wanted to create a JFileChooser which i have but i want to choose only in one directory like i have the directory called "Saves" and i want the person who open the JFileChooser can only access txt inside the directory call "Saves". They cant acess anything else only the directory i set.
I wanted to only access txt and cant acess neither another directorys neither other paths
I researched a lot but i couldn't find anything. If you know about something else like another choose please help me! Thank you.
A custom
FileSystemViewcan be used to tweak what the user can see and where they can navigate. For example, this is a simple implementation that pretends that the passed-in directory is the root (and home) directory and has no parent (note that the majority of the methods just delegate to the system file system view):(Only tested quickly on Linux, other OS might require additional changes to some overrides).
Note that you can further restrict what directories the user can visit by overriding
isTraversable()and even restrict what they see by overridinggetFiles().You can use this custom file system view in your
JFileChooserlike this: