我有一个VBox,我添加了50个标签。考虑到它被包装在ScrollPane中,我认为它允许我向下滚动以查看其余数据,但它不允许它。
当我通过Scene Builder构建它时,它被配置为XML。
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="454.0" prefWidth="641.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<VBox layoutX="111.0" layoutY="96.0" prefHeight="262.0" prefWidth="100.0">
<children>
<Label contentDisplay="TOP" style="-fx-font-size: 20;" text="Stack" />
<VBox fx:id="stackBox" alignment="BOTTOM_LEFT" prefHeight="284.0" prefWidth="149.0" style="-fx-border-color: black; -fx-background-color: lightgrey;" />
</children>
</VBox>
<VBox layoutX="298.0" layoutY="47.0" prefHeight="379.0" prefWidth="198.0">
<children>
<Label style="-fx-font-size: 20;" text="Heap" />
<ScrollPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="341.0" prefWidth="202.0" vbarPolicy="ALWAYS">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
<children>
<VBox fx:id="heapBox" prefHeight="284.0" prefWidth="149.0" style="-fx-border-color: black; -fx-background-color: lightgrey;" />
</children>
</AnchorPane>
</content>
</ScrollPane>
</children>
</VBox>
</children>
</AnchorPane>
由于VBox中有50个元素,它应该允许我向下滚动以查看剩余的32个元素,但是可以看出,滚动条不允许它。
在这种情况下可以做些什么?
答案 0 :(得分:2)
从min
内的pref
移除AnchorPane
和ScrollPane
尺寸值。然后,您的AnchorPane
可能符合ScrollPane
内容。
<AnchorPane>
<children>
<VBox fx:id="heapBox" prefHeight="284.0" prefWidth="149.0" style="-fx-border-color: black; -fx-background-color: lightgrey;" />
</children>
</AnchorPane>