I'm trying to definde the onAction accion for a Button done in scalafx but I can't make it to work.
package App.Desktop
import javafx.event.EventHandler
import scalafx.event.ActionEvent
import scalafx.scene.control.Button
class Window() {
btn_YES.onAction = (event: ActionEvent) =>
new EventHandler[ActionEvent] {
override def handle(event: ActionEvent) {
/*Do something*/
}
}
}
}
I've done this but I get an error
Error: type mismatch;
found : scalafx.event.ActionEvent => javafx.event.EventHandler[scalafx.event.ActionEvent]
required: javafx.event.EventHandler[javafx.event.ActionEvent]
btn_YES.onAction = (event: ActionEvent) => new EventHandler[ActionEvent]
I also tried to use the javafx.event.ActionEvent
instead of scalafx
but it doesn't work either.
Any clue?
Thanks
import scalafx.Includes._
- it will add some implicit conversions, which I think is necessary for the second version (with a function rather than anEventHandler
). Generally speaking, this import should always be used in ScalaFX code. – Economizer