gpt4 book ai didi

JavaFX FlowPane 自动调整大小

转载 作者:行者123 更新时间:2023-11-30 08:16:50 27 4
gpt4 key购买 nike

我遇到的问题是 FlowPane 留下了很多多余的空间,它可能是弹出窗口,尽管我认为弹出窗口大小就是内容大小。

为了调试,我将文本包装在 BorderPane 中以显示文本的边界。

我关注的组件是错误弹出窗口。

ScreenshotCSS

.warning-popup {
-fx-padding: 10px;
-fx-hgap: 10px;
-fx-vgap: 10px;
-fx-background-color: #704745;
-fx-border-color: #C8C8C8;
-fx-background-radius: 2px;
-fx-border-radius: 2px;
}


.warning-popup .text {
-fx-fill: #000000;
}

Java代码

public static void showWarningPopup(Node owner, String message, double screenX, double screenY) {
// create message text
Text text = new Text(message);
text.getStyleClass().add("text");
// wrap text in container
Pane textContainer = new BorderPane(text);
textContainer.setStyle("-fx-background-color: orange;");
// create error image
ImageView image = new ImageView("/resources/error-14.png");
image.getStyleClass().add("image-view");
// create content
FlowPane content = new FlowPane(image, textContainer);
content.getStyleClass().add("warning-popup");
content.autosize();
// create and show the popup
Popup popup = new Popup();
popup.setHideOnEscape(true);
popup.setAutoHide(true);
popup.setAutoFix(true);
popup.getContent().add(content);
popup.show(owner, screenX, screenY);
}

感谢您提前提供的任何帮助:)

最佳答案

背景

您遇到的问题是由于 FlowPane 的默认 WrapLength 设置为 400。此属性还将 FlowPane 的宽度设置为400

来自文档:

FlowPane's prefWrapLength property establishes it's preferred width (for horizontal) or preferred height (for vertical).

解决方案

您可以使用以下方法将wrapLength减少到所需的值

flowPane.setPrefWrapLength(YOUR_VALUE);

关于JavaFX FlowPane 自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29537264/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com