gpt4 book ai didi

尽管指定了 USE_COMPUTED_SIZE,JavaFX 和 Scene Builder 仍会剪辑场景边缘

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:27:40 24 4
gpt4 key购买 nike

我正在使用 Scene Builder (v11.0.0) 为 JavaFX (v12) 中的场景创建 FXML 文件,但是,尽管指示所有容器 USE_COMPUTED_SIZE 以获得首选的宽度和高度,渲染的场景(如在 Scene Builder 中所见,以及作为加载这些 FXML 文件的 JavaFX 应用程序运行时)在右侧和底部边缘被剪裁,以便切掉一些节点。

在 Scene Builder 中,渲染器似乎必须知道场景不符合允许的边界,因为编辑器显示蓝色边界标记,这些标记明显超出了渲染矩形。

在场景生成器中查看

Screenshot of the view in Scene Builder, showing the form design has been clipped at the right and bottom edges, followed by a dark boundary showing where the content ought to be, and then blue boundary markers showing the extent of that boundary.

Scene Builder 中的 View 显示底部需要更多空间以便为按钮提供足够的空间(按钮的底部边缘和 TitledPane 的下边缘缺失)。右侧需要更多空间以适应 DatePickerTitledPane 的右边缘。蓝色边界标记清楚地显示了实际内容结束的位置,因此不清楚为什么显示区域被计算为比这短几个像素。

Java应用程序运行 View

Screenshot of the scene rendered within a Java application, the form design clipped at the right and bottom edges, very similar to the degree of clipping seen in Scene Builder.

一旦 FXML 文件用于填充 JavaFX 应用程序中的窗口,就会看到同样的事情:窗口的计算大小是一些太少的像素,无法正确适应整个场景。

如果已正确计算蓝色边界标记以显示需要额外的显示区域宽度和高度,我如何告诉 FXML 在渲染时需要此额外空间?

这是 Scene Builder、FXML 或 JavaFX 中的已知错误/限制吗?或者除了为首选尺寸选择 USE_COMPUTED_SIZE 之外,我还需要做些什么吗?

为了明确这一点,请参阅下面的示例 FXML,它显示了所说明的问题。

场景.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TitledPane animated="false" collapsible="false" text="untitled">
<content>
<HBox>
<children>
<fx:include source="subscene.fxml" />
</children>
</HBox>
</content>
</TitledPane>
<TitledPane animated="false" collapsible="false" text="untitled">
<content>
<HBox>
<children>
<fx:include source="subscene.fxml" />
</children>
</HBox>
</content>
</TitledPane>
<TitledPane animated="false" collapsible="false" text="untitled">
<content>
<HBox alignment="BASELINE_RIGHT">
<children>
<Button mnemonicParsing="false" text="Button" />
<Button mnemonicParsing="false" text="Button" />
</children>
</HBox>
</content>
</TitledPane>
</children>
</VBox>

子场景.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>


<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label text="Label" />
<DatePicker />
</children>
</VBox>

最佳答案

这确实是 JavaFX 中的一个错误,特别是 DatePicker,因为这个简单的示例可以重现该问题:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.DatePicker;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) {
VBox root = new VBox(new DatePicker());

// Problem shows up when using USE_COMPUTED_SIZE (the default) as well
root.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
root.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);

primaryStage.setScene(new Scene(root));
primaryStage.show();
}

}

导致:

image showing improperly sized date picker parent

注意:将 DatePicker 放入哪个父级似乎无关紧要。其他控件也不会出现此问题。

此问题的解决方法似乎是在调用 show() 之后调用 Window.sizeToScene()。我不明白为什么这会有所作为,但确实如此。不幸的是,这只会对实际应用有帮助,对 Scene Builder 没有帮助。

关于尽管指定了 USE_COMPUTED_SIZE,JavaFX 和 Scene Builder 仍会剪辑场景边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55403477/

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