- 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
Advertisements