How to add a JavaFX ActionEvent EventHandler to a MenuItem in Scala

As a quick note to self, this is how you add an ActionEvent EventHandler to a MenuItem in JavaFX, when writing JavaFX code in Scala:

menuItem.setOnAction(new EventHandler[ActionEvent]() {
    @Override def handle(e: ActionEvent) {
        println("put your action here ...")
    }
})

If you have a reference to a MenuItem named menuItem, all you have to do now is implement the handle method.

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.