To let a user choose a file, directory or multiple files, use the
FileChooser.chooseFiles() method. This method has multiple overloads; the best method to use is the one which returns void and takes a callback receiving the list of selected files as a parameter. This is the only overload which will display a native file open dialog on Mac OS X.
The FileChooserDescriptor class allows you to control which files can be selected. The constructor parameters specify whether files and/or directories can be selected, and whether multiple selection is allowed. For more fine-grained control over the allowed selection, you can overload the
isFileSelectable() method. You can also customize the presentation of files by overloading getIcon(), getName() and getComment() methods on FileChooserDescriptor. Note that the native Mac OS X file chooser does not support most of the customizations, so if you rely on them, you need to use an overload of
chooseFiles() which displays the standard IntelliJ IDEA dialog.
A very common way of using file choosers is to use a text field for entering the path with an ellipsis button ("...") for showing the file chooser. To create such a control, use the TextFieldWithBrowseButton component and call the addBrowseFolderListener() method on it to set up the file chooser. As an added bonus, this will enable filename completion when entering paths in the text box.