对于内容较宽的HBox儿童,将忽略maxWidth.
例如,下面的中间窗格太大,在右列(窗格)下方延伸:
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="1000.0" prefWidth="1236.0">
<children>
<Pane fx:id="leftPane" maxHeight="10000.0" maxWidth="120.0" minHeight="400.0" minWidth="100.0" prefHeight="10000.0" prefWidth="120.0"/>
<Pane fx:id="centerPane" maxHeight="10000.0" maxWidth="10000.0" minHeight="400.0" minWidth="120.0" prefHeight="10000.0" >
</Pane>
<Pane fx:id="rightPane" maxHeight="10000.0" maxWidth="120.0" minHeight="400.0" minWidth="100.0" prefHeight="10000.0" prefWidth="120.0" />
</children>
</HBox>
Run Code Online (Sandbox Code Playgroud)
没有冲突的CSS,例如定义百分比或以其他方式设置内容宽度.
有没有办法让JavaFX每次子内容更改时重新计算子窗格大小,而不会超过父级的maxWidth?
这个类可以直接用于需要儿童绝对定位的情况,因为除了将可调整大小的儿童调整到他们喜欢的大小之外它不会执行布局.由于窗格在布局期间单独离开位置,因此应用程序负责定位子项.
因此,您无法通过将基本窗格用作子项来达到目标.最好尝试使用StackPanes:
堆栈窗格的父级将在布局期间调整堆栈窗格可调整大小范围内的堆栈窗格.
stackpane的无界最大宽度和高度表示父节点可以调整其大小超出其首选大小以填充分配给它的任何空间.
看看这个例子(我为StackPanes添加了背景颜色,因为我使用了SceneBuilder来测试行为)并告诉我它是否满足您的需求:
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="1000.0" prefWidth="1236.0" style="-fx-background-color: lightblue;" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<children>
<StackPane fx:id="leftPane" maxHeight="10000.0" maxWidth="120.0" minHeight="400.0" minWidth="100.0" prefHeight="10000.0" prefWidth="120.0" style="-fx-background-color: red;" />
<StackPane fx:id="centerPane" maxHeight="10000.0" maxWidth="10000.0" minHeight="400.0" minWidth="120.0" prefHeight="10000.0" style="-fx-background-color: white;">
<children>
<Label prefWidth="999.0" text="Label of example. Label of example. Label of example. Label of example. Label of example. Label of example. Label of example. Label of example. Label of example. Label of example. Label of example. " />
</children></StackPane>
<StackPane fx:id="rightPane" maxHeight="10000.0" maxWidth="120.0" minHeight="400.0" minWidth="100.0" prefHeight="10000.0" prefWidth="120.0" style="-fx-background-color: green;" />
</children></HBox>
Run Code Online (Sandbox Code Playgroud)
您也可以使用其他Pane或Box组件.
更新:
前面的示例使中心窗格根据其子项的宽度动态调整,如果需要,可以满足父窗格,但永远不会超过其最大宽度.因此,如果您希望窗格始终填充其父级的宽度,则必须在中间窗格中添加足够大的首选宽度.
<StackPane fx:id="centerPane" maxHeight="10000.0" minHeight="400.0" prefHeight="10000.0" prefWidth="1000.0"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3418 次 |
| 最近记录: |