A bit different than what Howard suggested
import scala.swing._ object GUI extends SimpleGUIApplication { def top = new Frame { title="Test" import javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE peer.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE) override def closeOperation() { showCloseDialog() } private def showCloseDialog() { Dialog.showConfirmation(parent = null, title = "Exit", message = "Are you sure you want to quit?" ) match { case Dialog.Result.Ok => exit(0) case _ => () } } } }
Using DO_NOTHING_ON_CLOSE , you are given the opportunity to determine what should be done if the WindowEvent.WINDOW_CLOSING event WindowEvent.WINDOW_CLOSING received by a scala frame. When a scala frame receives a WINDOW_CLOSING event, it responds by calling closeOperation . Therefore, to display the dialog when the user tries to close the frame, it is enough to redefine closeOperation and implement the desired behavior.
source share