Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 单击javafx中菜单上的事件_User Interface_Javafx_Menubar_Mouseclick Event - Fatal编程技术网

User interface 单击javafx中菜单上的事件

User interface 单击javafx中菜单上的事件,user-interface,javafx,menubar,mouseclick-event,User Interface,Javafx,Menubar,Mouseclick Event,我想做一个程序,如果用户点击菜单项,我们可以改变场景 例如,如果您单击菜单栏中的设置,同一窗口中会显示另一个场景,您可以更改节目的设置 注意:我的菜单没有任何菜单项。只有菜单栏 到目前为止我试了什么? 向HBox添加一些按钮并将其添加到边框窗格顶部。它确实可以工作,但看起来不像菜单。试图使它看起来像带有CSS的菜单,但没有工作 有什么问题? 问题是主菜单上的单击处理程序不工作。 若我将click事件处理程序分配给from Beggining按钮,它会工作,但不会在“设置”菜单上 想知道实现这个

我想做一个程序,如果用户点击菜单项,我们可以改变场景

例如,如果您单击菜单栏中的设置,同一窗口中会显示另一个场景,您可以更改节目的设置

注意:我的菜单没有任何菜单项。只有菜单栏

到目前为止我试了什么? 向HBox添加一些按钮并将其添加到边框窗格顶部。它确实可以工作,但看起来不像菜单。试图使它看起来像带有CSS的菜单,但没有工作

有什么问题? 问题是主菜单上的单击处理程序不工作。 若我将click事件处理程序分配给from Beggining按钮,它会工作,但不会在“设置”菜单上


想知道实现这个想法的最佳方法是什么吗?

下面是我以前项目的一部分。MenuItem在另一个类中,我在main中调用一个方法来切换场景

我有两个页面选择和信息,都有自己的容器和场景以及样式表。选择页面是在开始和I开关信息页面显示的初始页面

settingsMenuItem.setOnAction(e -> {
    e.consume();
    Launcher.selectionPage();
});
我的主要班级:

public class Launcher extends Application {

    private static FlowPane selectionPane;
    private static BorderPane infoPane;
    private static Scene selectionScene, infoScene;
    private static Stage theStage;
    private static String selectionCSS;
    private static String informationCSS;

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

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

        //Global reference needed to switch scenes in another method.
        this.theStage = primaryStage;

        //Declares resources, in this case stylesheet. Declared here to be applied in another method 
        selectionCSS = this.getClass().getResource("/views/SelectionStyle.css").toExternalForm();
        informationCSS = this.getClass().getResource("/views/InformationStyle.css").toExternalForm();

        //Initial page setup
        selectionPane = new SelectionPage();
        selectionScene = new Scene(selectionPane, 500, 500);
        selectionScene.getStylesheets().add(selectionCSS);

        //Stage setup
        primaryStage.setScene(selectionScene);
        primaryStage.show();
    }


    //Changes page
    public static void informationPage(String starSign) {

        infoPane = new InformationPage();
        infoScene = new Scene(infoPane, 500, 270);
        infoScene.getStylesheets().add(informationCSS);
        theStage.setScene(infoScene);
    }
}

已经一年多了,但这里有一个简单的解决方案,可以让
菜单
可以点击

<MenuBar>
        <Menu>
            <graphic>
                <Label fx:id="yourId" text="Your Text here" onMouseClicked="#mouseClickedEvent"/>
            </graphic>
        </Menu>
</MenuBar>

如果菜单为空,则不会生成事件(很遗憾)。您最好的选择可能是在
HBox
(或
工具栏
)中添加一些按钮(或者可能只是标签?),并按照您的描述将它们设置为菜单样式。我建议你尝试一下,如果你不能让它按照你想要的方式工作,那么就在你尝试的时候发布一个具体的问题。