ScrollPane不允许向下滚动查看其内容

ScrollPane不允许向下滚动查看其内容

问题描述:

我有一个VBox,我已经添加了50个标签。考虑到它被包装在ScrollPane中,我认为它可以让我向下滚动查看其余数据,但它不允许。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> 

这是目前是什么样子: enter image description here

由于有在垂直框50个元素,它应该允许我向下滚动才能看到剩余的32个元素,而是因为它可以看,滚动条不允许。

在这种情况下可以做些什么?

删除minpref尺寸值从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> 
+0

谢谢,这工作:) –