【发布时间】:2020-08-18 10:13:23
【问题描述】:
我是 JavaFx 的新手,并尝试使用三个 StackPane 构建以下屏幕,这些 StackPane 可以根据窗口大小动态增长和缩小宽度和高度。我尝试了不同的方法,但无法做到这一点。我也尝试使用 AnchorPane 约束。这是我想要实现的图像和相应的 FXML。这是我在这些窗格之间寻找的约束
- 左窗格具有最大宽度 (300px) 和最小 150
- 左右 (2) 堆栈窗格之间的距离应保持不变
- 右侧顶部和底部堆栈窗格之间的距离应保持不变
- 左侧顶部堆栈窗格的最大高度为 250 像素
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="437.0"
prefWidth="736.0" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<StackPane layoutX="14.0" layoutY="27.0" prefHeight="405.0"
prefWidth="223.0" style="-fx-background-color: white;"
AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="15.0"
AnchorPane.topAnchor="20.0">
<effect>
<DropShadow />
</effect>
</StackPane>
<StackPane layoutX="251.0" layoutY="21.0" prefHeight="119.0"
prefWidth="470.0" style="-fx-background-color: #ffffff;"
AnchorPane.leftAnchor="251.0" AnchorPane.rightAnchor="15.0"
AnchorPane.topAnchor="21.0">
<effect>
<DropShadow />
</effect>
</StackPane>
<StackPane layoutX="251.0" layoutY="150.0"
prefHeight="269.0" prefWidth="470.0"
style="-fx-background-color: #ffffff;" AnchorPane.bottomAnchor="13.0"
AnchorPane.leftAnchor="251.0" AnchorPane.rightAnchor="15.0">
<effect>
<DropShadow />
</effect>
</StackPane>
</children>
</AnchorPane>
【问题讨论】:
-
您希望 3 个堆栈窗格在窗口大小发生变化时表现如何?
-
- 左窗格具有最大宽度 (300 像素) 和最小 150 - 左右 (2) 堆栈窗格之间的距离应保持不变 - 堆栈窗格右顶部和底部之间的距离应保持不变 - 左侧顶部堆栈窗格的最大高度为 250 像素
-
请edit您的问题并添加基本信息。 “左侧和右侧 (2) 堆栈窗格之间的距离应保持恒定 - 右侧顶部和底部堆栈窗格之间的距离应保持恒定”我不清楚。
-
@c0der 感谢您的指点。将这些详细信息添加到问题中