Skip to content

Commit

Permalink
add a scrollbar for long popup messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Jan 13, 2024
1 parent e184307 commit 5a12649
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions megameklab/src/megameklab/ui/PopupMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
Expand Down

0 comments on commit 5a12649

Please sign in to comment.