diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/windows/GenericMessageWindow.java b/desktop/src/main/java/haveno/desktop/main/overlays/windows/GenericMessageWindow.java index 01d119a479..a3887eec38 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/windows/GenericMessageWindow.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/windows/GenericMessageWindow.java @@ -18,6 +18,7 @@ package haveno.desktop.main.overlays.windows; import haveno.desktop.main.overlays.Overlay; +import haveno.desktop.util.GUIUtil; import haveno.desktop.util.Layout; import javafx.scene.control.Label; import javafx.scene.control.TextArea; @@ -28,6 +29,7 @@ import static haveno.desktop.util.FormBuilder.addTextArea; public class GenericMessageWindow extends Overlay { private String preamble; + private static final double MAX_TEXT_AREA_HEIGHT = 250; public GenericMessageWindow() { super(); @@ -57,17 +59,7 @@ public class GenericMessageWindow extends Overlay { textArea.setText(message); textArea.setEditable(false); textArea.setWrapText(true); - // sizes the textArea to fit within its parent container - double verticalSizePercentage = ensureRange(countLines(message) / 20.0, 0.2, 0.7); - textArea.setPrefSize(Layout.INITIAL_WINDOW_WIDTH, Layout.INITIAL_WINDOW_HEIGHT * verticalSizePercentage); - } - - private static int countLines(String str) { - String[] lines = str.split("\r\n|\r|\n"); - return lines.length; - } - - private static double ensureRange(double value, double min, double max) { - return Math.min(Math.max(value, min), max); + textArea.setPrefWidth(Layout.INITIAL_WINDOW_WIDTH); + GUIUtil.adjustHeightAutomatically(textArea, MAX_TEXT_AREA_HEIGHT); } } diff --git a/desktop/src/main/java/haveno/desktop/util/GUIUtil.java b/desktop/src/main/java/haveno/desktop/util/GUIUtil.java index a17262f532..34391cc233 100644 --- a/desktop/src/main/java/haveno/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/haveno/desktop/util/GUIUtil.java @@ -1181,6 +1181,10 @@ public class GUIUtil { } public static void adjustHeightAutomatically(TextArea textArea) { + adjustHeightAutomatically(textArea, null); + } + + public static void adjustHeightAutomatically(TextArea textArea, Double maxHeight) { textArea.sceneProperty().addListener((o, oldScene, newScene) -> { if (newScene != null) { // avoid javafx css warning @@ -1192,7 +1196,8 @@ public class GUIUtil { textArea.prefHeightProperty().bind(Bindings.createDoubleBinding(() -> { Insets padding = textArea.getInsets(); double topBottomPadding = padding.getTop() + padding.getBottom(); - return textArea.getFont().getSize() + text.getBoundsInLocal().getHeight() + topBottomPadding; + double prefHeight = textArea.getFont().getSize() + text.getBoundsInLocal().getHeight() + topBottomPadding; + return maxHeight == null ? prefHeight : Math.min(prefHeight, maxHeight); }, text.boundsInLocalProperty())); text.boundsInLocalProperty().addListener((observableBoundsAfter, boundsBefore, boundsAfter) -> {