javafx要在scrollPanel中使用Panel的滚动方法setPannable(true)不起作用

时间:2014-12-24 11:40:56

标签: javafx jscrollpane

我在滚动面板中放置一个可伸缩的窗格然后滚动方式后,他的更大的scrollpanel setPannable(true)方法不起作用,我不知道如何解决,希望得到帮助

public class CreateAdvancedStage extends Application {
private void init(Stage primaryStage) {
    BorderPane root = new BorderPane();
    root.setPrefSize(200, 220);
    primaryStage.setScene(new Scene(root));
    ScrollPane scrolPanel = new ScrollPane();
    scrolPanel.setPannable(true);//it do not work
    scrolPanel.setContent(getCenterPane());
    root.setCenter(scrolPanel);

}
Pane panel;
int tag = 10;
public Pane getCenterPane() {
    panel = new Pane();
    panel.setStyle("-fx-background-color:red");
    panel.setPrefSize(100, 100);
    panel.setOnScroll(new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent t) {
            System.out.println("OnScroll");
            //this to set panSize
            if (panel != null) {
                panel.setPrefSize(100 + tag, 100 + tag);
                tag++;
            }
        }
    });
    return panel;
}

@Override
public void start(Stage primaryStage) throws Exception {
    init(primaryStage);
    primaryStage.show();
}
public static void main(String[] args) {
    launch(args);
}

}

0 个答案:

没有答案