From fded830f3d1aff4df4a639b6e5701c3668a61809 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 6 Apr 2020 16:49:29 -0400 Subject: 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 --- .../main/java/bjc/utils/gui/SimpleFileChooser.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'base/src/main/java/bjc/utils/gui/SimpleFileChooser.java') 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(); + } } -- cgit v1.2.3