From 5a126494dbe38b674d1965111083f3f270badb49 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 13 Jan 2024 23:49:18 +0100 Subject: [PATCH] add a scrollbar for long popup messages --- .../src/megameklab/ui/PopupMessages.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/megameklab/src/megameklab/ui/PopupMessages.java b/megameklab/src/megameklab/ui/PopupMessages.java index 18045ca07..aff340192 100644 --- a/megameklab/src/megameklab/ui/PopupMessages.java +++ b/megameklab/src/megameklab/ui/PopupMessages.java @@ -102,15 +102,31 @@ public static void showUncaughtException(Component parent, Throwable throwable) // ############ Internal message handlers private static void showErrorMessage(Component parent, String message) { - JOptionPane.showMessageDialog(parent, message, "MML encountered a problem", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(parent, possiblyWrapInScrollBar(message), + "MML encountered a problem", JOptionPane.ERROR_MESSAGE); } private static void showWarningMessage(Component parent, String message) { - JOptionPane.showMessageDialog(parent, message, "Warning", JOptionPane.WARNING_MESSAGE); + JOptionPane.showMessageDialog(parent, possiblyWrapInScrollBar(message), + "Warning", JOptionPane.WARNING_MESSAGE); } private static void showInfoMessage(Component parent, String message) { - JOptionPane.showMessageDialog(parent, message, "Information", JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(parent, possiblyWrapInScrollBar(message), + "Information", JOptionPane.INFORMATION_MESSAGE); + } + + private static Object possiblyWrapInScrollBar(String message) { + if (message.length() < 200) { + return message; + } else { + JTextArea textArea = new JTextArea(message); + JScrollPane scrollPane = new JScrollPane(textArea); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + scrollPane.setPreferredSize(new Dimension(600, 500)); + return scrollPane; + } } private PopupMessages() { }