0

我对如何添加ScrollPane到主舞台很感兴趣。当我减小主页的大小时,我想ScrollPane用来在主舞台上移动。有什么例子吗?

4

2 回答 2

2

如果您的内容ScrollPane大于 的允许大小ScrollPaneScrollPane则应自动附加滚动条。这是一个例子:

public class JFXScroll extends Application {

    @Override
    public void start(Stage stage) throws Exception {

        BorderPane main = new BorderPane();

        ScrollPane scroll = new ScrollPane();
        VBox box = new VBox();

        // Demo purposes; Wouldn't normally do this - just let the box automatically fit the content
        box.setPrefSize(1000, 500);
        box.setEffect(new ColorInput(0,0,1000,500,Color.LIME));

        scroll.setContent(box);

        main.setLeft(new Label("Left Content"));
        main.setCenter(scroll);

        Scene scene = new Scene(main, 300, 250);
        stage.setScene(scene);
        stage.show();


    }
    public static void main(String[] args) {
        launch(args);
    }
}
于 2013-06-05T20:44:44.800 回答
0

stage.setScene(new ScrollPane(yourContent));应该这样做。当然,您的内容应该有适当的最小、最大和首选尺寸

于 2013-06-05T15:19:24.637 回答