JavaFX 2.0 Activating a Menu like a MenuItem

前端 未结 5 2035
夕颜
夕颜 2020-12-01 12:51

I\'m making a MenuBar, and I wan\'t the functionality to press a Menu like: \"File\" and then execute a action. Such like opening an other fxml, or

5条回答
  •  情歌与酒
    2020-12-01 13:26

    Recently i had the same problem, this is what i did

    @FXML private Menu myMenu;
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
    
        myMenu.setGraphic(
            ButtonBuilder.create()
                .text("btnText")
                .onAction(new EventHandler(){
                    @Override public void handle(ActionEvent t) {
                        //TODO
                 } })
                .build()
        );
    }
    

提交回复
热议问题