-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFolderPicker.java
More file actions
25 lines (21 loc) · 910 Bytes
/
FolderPicker.java
File metadata and controls
25 lines (21 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import javax.swing.*;
import java.io.File;
public class FolderPicker {
public static String open() {
// Create a JFileChooser object
JFileChooser folderChooser = new JFileChooser();
// Set the selection mode to directories only
folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// Show the open dialog and store the user's response
int result = folderChooser.showOpenDialog(null);
// Check if a folder was selected
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFolder = folderChooser.getSelectedFile();
//System.out.println("Selected folder: " + selectedFolder.getAbsolutePath());
return selectedFolder.getAbsolutePath();
} else {
//System.out.println("Folder selection was cancelled.");
return "";
}
}
}