diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-04-06 16:49:29 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-04-06 16:49:29 -0400 |
| commit | fded830f3d1aff4df4a639b6e5701c3668a61809 (patch) | |
| tree | 63e654615b9bf3f14fec4787f00d4b2dad7075e8 /base/src/main/java/bjc/utils/gui/SimpleFileChooser.java | |
| parent | 7b6c29bf9f82d87225a1206d451381e9de84e039 (diff) | |
Update UI controls
Add an additional UI control (a button that has a keystroke bound to
it), and add the ability to get a directory picker from
SimpleFileChooser
Diffstat (limited to 'base/src/main/java/bjc/utils/gui/SimpleFileChooser.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/gui/SimpleFileChooser.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java b/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java index 2bdd792..01cd37f 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java +++ b/base/src/main/java/bjc/utils/gui/SimpleFileChooser.java @@ -195,4 +195,26 @@ public class SimpleFileChooser { return files.getSelectedFile(); } + + /** + * Show a dialog box to pick a directory. + * + * @param parent + * The component to use as the parent for the dialog. + * @param title + * The title of the dialog for prompting. + * @return The directory picked, if the user picked one; null if they didn't. + */ + public static File pickDirectory(final Component parent, final String title) { + if (title == null) throw new NullPointerException("Title must not be null"); + + final JFileChooser files = new JFileChooser(); + files.setDialogType(JFileChooser.OPEN_DIALOG); + files.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + files.setDialogTitle(title); + + files.showOpenDialog(parent); + + return files.getSelectedFile(); + } } |
