Orange Receptacle
Orange Receptacle

Reputation: 1183

ScrollPane doesn't allow scrolling down to see its contents

I have a VBox which I have added 50 Labels to. Considering it's wrapped within a ScrollPane, I thought that it would allow for me to scroll down to see the rest of the data, but it doesn't allow it.

As I'm building this through Scene Builder, it is configured as 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>

This is currently what it looks like: enter image description here

As there are 50 elements in the VBox, it should allow for me to scroll down to see the remaining 32 elements, but as it can be seen, the scrollbar doesn't allow it.

What can be done in this circumstance?

Upvotes: 1

Views: 1954

Answers (1)

MBec
MBec

Reputation: 2210

Remove min and pref size values from your AnchorPane inside ScrollPane. Then your AnchorPane could fit to ScrollPane content.

<AnchorPane>
   <children>
      <VBox fx:id="heapBox" prefHeight="284.0" prefWidth="149.0" style="-fx-border-color: black; -fx-background-color: lightgrey;" />
   </children>
</AnchorPane>

Upvotes: 2

Related Questions