为什么JavaFXScrollPane pannable不工作,为什么圆圈周围的框不工作?

为什么JavaFXScrollPane pannable不工作,为什么圆圈周围的框不工作?,javafx,fxml,Javafx,Fxml,这是我的主课 package software; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; import javafx.fxml.FXMLLoader; public class FXMLExample extends Application {

这是我的主课

package software;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.fxml.FXMLLoader;

    public class FXMLExample extends Application {

        public static void main(String[] args) {
            launch(args);
        }

        @Override
        public void start(Stage primaryStage) {
            try {
                ScrollPane root = (ScrollPane)FXMLLoader.load(getClass().getResource("fxml_example.fxml"));
                Scene scene = new Scene(root, 200, 200);
                primaryStage.setScene(scene);
                primaryStage.show();
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
}
FXML文件

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

<?import javafx.scene.shape.*?>
<?import javafx.scene.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<ScrollPane fx:id="sp" hbarPolicy="NEVER" maxHeight="-Infinity"
    maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
    pannable="true" prefHeight="400.0" prefWidth="600.0" vbarPolicy="NEVER"
    xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
    fx:controller="software.FXMLExampleController">
    <content>
        <Group>
            <children>
                <Circle fill="DODGERBLUE" radius="100.0" stroke="BLACK"
                    strokeType="INSIDE" />
            </children>
        </Group>
    </content>
</ScrollPane>
当鼠标滚轮缩小时,为什么长方体环绕实心圆?

为什么“可平移”设置不起作用?

您正在对整个滚动窗格应用缩放。。。因此滚动窗格本身正在改变大小。您看到的框是滚动窗格本身。它永远不会滚动,因为内容永远不会大于视口(因为整个滚动窗格和内容都在一起调整大小)。你想缩放内容(但我现在没有时间来找出完整的修复方法)。谢谢你修复了缩放部分。现在仍然需要弄清楚为什么pannable不起作用。我发现了问题所在。似乎如果场景图不在窗格外,“可平移”功能将无法工作。场景图必须具有在scrollpane外部渲染的元素,“pannable”功能才能开始工作。
package software;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.input.ScrollEvent;
import javafx.stage.Stage;

public class FXMLExampleController {

    @FXML
    ScrollPane sp;

    final double SCALE_DELTA = 1.1;

    @FXML
    protected void initialize() {

        double scrollDelta = 0;

        System.out.println("In initialize() method");

        System.out.println("sp:" + sp);

        // boardersp.sceneProperty().addListener( (o, oldEvent, newEvent) ->
        // {
        System.out.println("Gleep000");
        System.out.println("Gleep000.0");
        System.out.println("sp: " + sp.getClass().getName());
        sp.sceneProperty();
        System.out.println("Gleep001");
        System.out.println("Gleep002");
        sp.sceneProperty().addListener((o, oldEvent, newEvent) -> {
            if (oldEvent != null) {
                // remove your stuff from the scene
                System.out.println("In addListner() remove");
            }
            if (newEvent != null) {
                // add your stuff to the scene
                System.out.println("In addListner() add");
                newEvent.setOnScroll(new EventHandler() {
                    @Override
                    public void handle(Event event) {
                        System.out.println("In handle scroll event");

                        ScrollEvent se = (ScrollEvent) event;
                        double scrollDelta = ((ScrollEvent) event).getDeltaY();
                        System.out.println("\tscrollDelta: " + scrollDelta);

                        if (scrollDelta == 0) {
                            return;
                        }

                        double scaleFactor = (se.getDeltaY() > 0) ? SCALE_DELTA : 1 / SCALE_DELTA;

                        System.out.println("\tscaleFactor: " + scaleFactor);
                        // amount of scrolling in each direction in
                        // scrollContent coordinate
                        // units
                        // Point2D scrollOffset =
                        // figureScrollOffset(topScrollPaneGroup,
                        // topScrollPane);

                        System.out.println("\tBefore::boardersp.getTranslateX: " + sp.getTranslateX());
                        System.out.println("\tBefore::boardersp.sp.getScaleX: " + sp.getScaleX());
                        sp.setScaleX(sp.getScaleX() * scaleFactor);
                        System.out.println("\tAfter::boardersp.getTranslateX: " + sp.getTranslateX());
                        System.out.println("\tAfter::boardersp.sp.getScaleX: " + sp.getScaleX());

                        System.out.println("\tBefore::boardersp.getTranslateY: " + sp.getTranslateY());
                        System.out.println("\tBefore::boardersp.sp.getScaleY: " + sp.getScaleY());
                        sp.setScaleY(sp.getScaleY() * scaleFactor);
                        System.out.println("\tAfter::boardersp.getTranslateY: " + sp.getTranslateY());
                        System.out.println("\tAfter::boardersp.sp.getScaleY: " + sp.getScaleY());
                    }
                });
            }
        });
    }

}