From e4540046a50439fbf4994bdf810e73e98dd88795 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Tue, 23 May 2023 12:14:22 +0200 Subject: [PATCH] IDEA-305104 Increase the height of the scrollable popup GitOrigin-RevId: cd98ce99568e7244da42a51a5cf4a9df743af05e --- .../ui/messages/AlertMessagesManager.kt | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/messages/AlertMessagesManager.kt b/platform/platform-impl/src/com/intellij/ui/messages/AlertMessagesManager.kt index 954bbf6b236a..3dbce9580d7c 100644 --- a/platform/platform-impl/src/com/intellij/ui/messages/AlertMessagesManager.kt +++ b/platform/platform-impl/src/com/intellij/ui/messages/AlertMessagesManager.kt @@ -367,13 +367,7 @@ private class AlertDialog(project: Project?, myMessageComponent = messageComponent singleSelectionHandler.add(messageComponent, false) - val lines = myMessage.length / 100 - val scrollPane = Messages.wrapToScrollPaneIfNeeded(messageComponent, 100, 15, if (lines < 4) 4 else lines) - if (scrollPane is JScrollPane) { - scrollPane.isOpaque = false - scrollPane.viewport.isOpaque = false - } - textPanel.add(wrapWithMinWidth(scrollPane)) + textPanel.add(wrapWithMinWidth(wrapToScrollPaneIfNeeded(messageComponent))) } textPanel.add(mySouthPanel, BorderLayout.SOUTH) @@ -425,6 +419,31 @@ private class AlertDialog(project: Project?, return dialogPanel } + private fun wrapToScrollPaneIfNeeded(messageComponent: JEditorPane): JComponent { + val width450 = JBUI.scale(450) + val size2D = messageComponent.font.size2D + val maximumHeight = (size2D * 9).toInt() + val preferred: Dimension = messageComponent.preferredSize + + if (preferred.height < maximumHeight) { + val columnLength = (1.2 * width450 / size2D).toInt() + if (messageComponent.document.length < columnLength * 8) { + return messageComponent + } + } + + val scrollPane = ScrollPaneFactory.createScrollPane(messageComponent, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED) + scrollPane.border = BorderFactory.createEmptyBorder(0, 0, 0, 0) + scrollPane.isOpaque = false + scrollPane.viewport.isOpaque = false + + val barWidth = UIUtil.getScrollBarWidth() + scrollPane.preferredSize = Dimension(preferred.width.coerceAtMost(width450) + barWidth, maximumHeight + barWidth) + + return scrollPane + } + private fun wrapWithMinWidth(scrollPane: JComponent) = object : Wrapper(scrollPane) { override fun setBounds(x: Int, y: Int, width: Int, height: Int) { super.setBounds(x, y, min(width, JBUI.scale(450)), height)