如何将ScrollPane添加到主阶段

时间:2013-06-05 12:41:58

标签: javafx-2 javafx javafx-8

我很感兴趣如何将ScrollPane添加到主舞台。我希望当我缩小主页面的大小以使用ScrollPane移动主舞台时。有什么例子吗?

2 个答案:

答案 0 :(得分:2)

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

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);
    }
}

答案 1 :(得分:0)

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

相关问题