JavaFX-如何居中滚动面板并在按钮上方设置左上方?

时间:2019-06-09 09:58:38

标签: java javafx

我有一个带一个按钮和一个滚动窗格的StackPane代码。我想将滚动窗格居中,并将按钮设置在左上方。我没有找到另一个将其居中的窗格,并将其设置在此窗格的左上方。每次都以所有节点为中心,或以所有节点为左上。

我的代码与Gradle一起运行,并在Intellij IDEA macOS版本中运行JavaFX库。

我的代码:

        primaryStage.setTitle("testJava");

        StackPane pane = new StackPane();

        Button button = new Button("test OK");
        StackPane.setAlignment(button, Pos.TOP_LEFT);

        CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("X");

        NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("Y");

        BarChart barChart = new BarChart(xAxis, yAxis);
        AreaChart areaChart = new AreaChart(xAxis, yAxis);

        VBox chartsBox = new VBox(barChart, areaChart);
        chartsBox.setAlignment(Pos.CENTER);

        ScrollPane scrollPane = new ScrollPane();

        scrollPane.setContent(chartsBox);
        StackPane.setAlignment(scrollPane, Pos.CENTER);

        pane.getChildren().addAll(button, scrollPane);

        Scene scene = new Scene(pane,750, 500);

        primaryStage.setMinWidth(750);
        primaryStage.setMinHeight(500);

        primaryStage.setScene(scene);
        primaryStage.show();

因此,我每次都将窗格置于所有节点的中心或置于所有节点的左上方。而且,我想将按钮设置为左上方,并将滚动窗格设置为中心。

0 个答案:

没有答案