I have a small database that adds labels to a VBox, which is in AnchorPane, which belongs to ScrollPane. Technically, it works fine, except that the scroll movement is minimal. Moving from top to bottom of the scroll bar is only few dozen pixels in movement.

I have tried chaning all the settings in properties in layout menu and nothing ever happens, except that it sometimes break and inverts the direction of scrolling.

What should I do to make scrollpane scroll much more?

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
  <children>
    <ScrollPane layoutX="100.0" layoutY="52.0" pannable="false" prefHeight="200.0" prefWidth="200.0" vmax="100.0">
      <content>
        <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
          <children>
            <VBox prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
              <children>
                <Label text="Label">
                  <font>
                    <Font size="50.0" fx:id="x1" />
                  </font>
                </Label>
                <Label font="$x1" text="Label" />
                <Label font="$x1" text="Label" />
                <Label font="$x1" text="Label" />
                <Label font="$x1" text="Label" />
              </children>
            </VBox>
          </children>
        </AnchorPane>
      </content>
    </ScrollPane>
  </children>
</AnchorPane>
有帮助吗?

解决方案

Recommended fix to your sample FXML:

  1. Don't set vmax on the vertical scroll.
  2. Add in more content (e.g. more labels), so there is actually something to scroll.
  3. Don't place the VBox holding your scrollable content inside an AnchorPane.

Try this version:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
  <ScrollPane layoutX="100.0" layoutY="52.0" pannable="false" prefHeight="200.0" prefWidth="200.0">
    <VBox prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <Label text="Label">
        <font>
          <Font size="50.0" fx:id="x1" />
        </font>
      </Label>
      <Label font="$x1" text="Label" />
      <Label font="$x1" text="Label" />
      <Label font="$x1" text="Label" />
      <Label font="$x1" text="Label" /><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/><Label font="$x1" text="Label"/>
    </VBox>
  </ScrollPane>
</AnchorPane>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top