Needs["JLink`"];
FileChooserDialog[] := FileChooserDialog["Select a file:", "Open", Directory[]];
FileChooserDialog[title_String, okText_String, dir_String] :=
JavaBlock[
Module[{dlg, chosenFile, result = Null},
InstallJava[];
dlg = JavaNew["javax.swing.JFileChooser"];
If[!JavaObjectQ[dlg],
Print["This function requires the Java Swing classes."];
Return[$Failed]
];
dlg@setCurrentDirectory[JavaNew["java.io.File", dir]];
dlg@setDialogTitle[title];
If[dlg@showDialog[Null, okText] === JFileChooser`APPROVEUOPTION,
chosenFile = dlg@getSelectedFile[];
If[chosenFile =!= Null,
result = chosenFile@getPath[]
]
];
result
]
]

FileChooserDialog[]


Back to main page