-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateFileChooser.pde
More file actions
38 lines (35 loc) · 1.27 KB
/
Copy pathcreateFileChooser.pde
File metadata and controls
38 lines (35 loc) · 1.27 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import javax.swing.JButton;
import javax.swing.JFileChooser;
class createFileChooser {
private JButton open;
private String fcName;
private String fcSelection;
private String selection;
public createFileChooser(String chooserName, String fileSelection){
fcName = chooserName;
fcSelection = fileSelection;
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new java.io.File("user.home"));
fc.setDialogTitle(fcName);
if (fcSelection == "FILES_AND_DIRECTORIES") {
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
}
if (fcSelection == "FILES_ONLY") {
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
if (fcSelection == "DIRECTORIES_ONLY") {
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
fc.setAcceptAllFileFilterUsed(false);
if (fc.showOpenDialog(open) == JFileChooser.APPROVE_OPTION) {
System.out.println("Dir: "
+ fc.getCurrentDirectory());
System.out.println("File: "
+ fc.getSelectedFile());
}
selection = fc.getSelectedFile().getAbsolutePath();
}
public String getSelection() {
return selection;
}
}