diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java index 85b9fa9..ea48977 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java @@ -49,6 +49,52 @@ public class SimpleDialogs { } /** + * Asks the user to pick an option from a series of choices. + * + * @param parent + * The parent frame for this dialog + * @param title + * The title of this dialog + * @param question + * The question being asked + * @param choices + * The available choices for the question + * @return The choice the user picked, or null if they didn't pick one + */ + @SuppressWarnings("unchecked") + public static <E> E getChoice(Frame parent, String title, + String question, E... choices) { + JDialog jd = new JDialog(parent, title, true); + jd.setLayout(new VLayout(2)); + + JPanel questionPane = new JPanel(); + + JLabel questionText = new JLabel(question); + JComboBox<E> questionChoices = new JComboBox<>(choices); + + questionPane.add(questionText); + questionPane.add(questionChoices); + + JPanel buttonPane = new JPanel(); + + JButton okButton = new JButton("Ok"); + okButton.addActionListener(e -> jd.dispose()); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(e -> jd.dispose()); + + buttonPane.add(cancelButton); + buttonPane.add(okButton); + + jd.add(questionPane); + jd.add(buttonPane); + + jd.pack(); + jd.setVisible(true); + + return (E) questionChoices.getSelectedItem(); + } + + /** * Get a integer from the user * * @param parent @@ -152,52 +198,6 @@ public class SimpleDialogs { } /** - * Asks the user to pick an option from a series of choices. - * - * @param parent - * The parent frame for this dialog - * @param title - * The title of this dialog - * @param question - * The question being asked - * @param choices - * The availible choices for the question - * @return The choice the user picked, or null if they didn't pick one - */ - @SuppressWarnings("unchecked") - public static <E> E getChoice(Frame parent, String title, - String question, E... choices) { - JDialog jd = new JDialog(parent, title, true); - jd.setLayout(new VLayout(2)); - - JPanel questionPane = new JPanel(); - - JLabel questionText = new JLabel(question); - JComboBox<E> questionChoices = new JComboBox<>(choices); - - questionPane.add(questionText); - questionPane.add(questionChoices); - - JPanel buttonPane = new JPanel(); - - JButton okButton = new JButton("Ok"); - okButton.addActionListener(e -> jd.dispose()); - JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(e -> jd.dispose()); - - buttonPane.add(cancelButton); - buttonPane.add(okButton); - - jd.add(questionPane); - jd.add(buttonPane); - - jd.pack(); - jd.setVisible(true); - - return (E) questionChoices.getSelectedItem(); - } - - /** * Show a error message to the user * * @param parent |
