- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get Directories from JFileChooser in Java
To get directories from JFileChoose, use the mode setFileSelectionMode −
JFileChooser file = new JFileChooser(); file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
The following is an example to get Directories from JFileChooser −
Example
import javax.swing.JFileChooser; public class SwingDemo { public static void main(String[] args) { JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(false); file.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int res = file.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { java.io.File f = file.getSelectedFile(); System.err.println(f.getPath()); } } }
Output
- Related Articles
- How to get the directories (only) from a folder using Java?
- How to get the names of the empty directories in a directory in Java?
- How to get all the directories and sub directories inside a path in C#?
- How to create directories (hierarchically) in Java?
- Get Base Root Directories of a System in Java
- How to enable multiple selections in a JFileChooser Dialog with Java?
- Get the path of the file selected in the JFileChooser component with Java
- How to enable the display of hidden files in a JFileChooser in Java?
- How to create FileFilter for JFileChooser in Java and display File Type accordingly?
- How to Protect Files and Directories from Deleting in Linux
- Create directories recursively in Java
- How to create Directories using the File utility methods in Java?
- How to get a list of all sub-directories in the current directory using Python?
- How to get first and last elements from ArrayList in Java?
- How to get a stream from Optional class in Java 9?

Advertisements