diff --git a/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java b/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java index 5956cc9e33..05a3149b80 100644 --- a/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java +++ b/designer-base/src/main/java/com/fr/design/components/notification/NotificationDialog.java @@ -32,6 +32,7 @@ import java.awt.event.MouseEvent; import java.net.URI; import java.util.Arrays; import java.util.List; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -151,18 +152,31 @@ public class NotificationDialog extends JDialog { } return new UILabel(LinkStrUtils.generateHtmlTag(messageModel.format())); }) + .collect(Collectors.toList()); + + Function calStandardWidth = e -> e > 4 ? 280 : 300; + + int widthUnit = messageComponents.stream() + .map((component) -> { + Dimension preferredSize = component.getPreferredSize(); + return preferredSize.getHeight(); + }) + .reduce(Double::sum) + .map(calStandardWidth) + .orElse(300); + + messageComponents = messageComponents.stream() .peek((component) -> { Dimension preferredSize = component.getPreferredSize(); double componentWidth = preferredSize.getWidth(); double componentHeight = preferredSize.getHeight(); - double widthFactor = Math.ceil(componentWidth / 300); double heightFactor = Math.ceil(componentHeight / 15); + double widthFactor = Math.ceil(componentWidth / widthUnit); int realHeight = (int) (heightFactor + widthFactor - 1) * 15; - component.setPreferredSize(new Dimension(300, realHeight)); - + component.setPreferredSize(new Dimension(widthUnit, realHeight)); }) .collect(Collectors.toList()); - + // 竖向排列 JPanel messageSummaryPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, VerticalFlowLayout.TOP, 0, 0); messageComponents.forEach(messageSummaryPanel::add); diff --git a/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java b/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java index 1536dd2622..b4ae293979 100644 --- a/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java +++ b/designer-base/src/test/java/com/fr/design/components/notification/NotificationDialogTest.java @@ -31,7 +31,7 @@ public class NotificationDialogTest { public void run(Object... args) { System.out.println("1111"); } - }, new NotificationMessage.LinkMessage("1111 2222 33333333 4444 555 6666 66555 888 999 333
3333", ""),new NotificationMessage.LinkMessage("display model2 test", "abc")); + }, new NotificationMessage.LinkMessage("1111 2222 33333333 4444 555 6666 66555 888 999 333
3333
444
555
", ""),new NotificationMessage.LinkMessage("display model2 test", "abc")); NotificationDialogProperties properties = new NotificationDialogProperties(frame, "test"); NotificationDialog dialog = new NotificationDialog(properties, Lists.newArrayList(model1, model2));