MenuBar协调JavaFx

时间:2017-05-04 15:31:24

标签: java javafx menu

我创建了最简单的程序,现在我想制作一个菜单。问题是我无法通过使用方法setLayoutX / setLayoutY更改菜单栏坐标。你怎么解决这个问题?建议请。

public class ForCyber extends Application {

    public void start(Stage primaryStage) throws Exception {
        init(primaryStage);
    }

    private void init(Stage primaryStage) {

        NumberAxis xAxis = new NumberAxis();
        NumberAxis yAxis = new NumberAxis();
        LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
        XYChart.Series series1 = new XYChart.Series();


        HBox root = new HBox();
        lineChart.getData().add(series1);

        root.getChildren().add(lineChart);
        Scene scene = new Scene(root, 650, 330);
        primaryStage.setScene(scene);


        for (int i = 0; i <10; i++) {
            series1.getData().add(new XYChart.Data<Number, Number>(i, i));
        }

        for (XYChart.Series<Number, Number> series : lineChart.getData()) {
            for (XYChart.Data<Number, Number> data : series.getData()) {
                StackPane stackPane = (StackPane) data.getNode();
                stackPane.setVisible(false);
            }
        }

        Menu fileMenu = new Menu("Data");
        fileMenu.getItems().add(new MenuItem("Test"));
        MenuBar menuBar = new MenuBar();
        menuBar.getMenus().addAll(fileMenu);
        menuBar.setLayoutX(123);
        menuBar.setLayoutY(400);
        root.getChildren().add(menuBar);
        primaryStage.show();

    }

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

}

0 个答案:

没有答案