private boolean maybeSave() { if (scribbleArea.isModified()) { QMessageBox.StandardButton ret; ret = QMessageBox.warning( this, tr("Scribble"), tr("The image has been modified.\n" + "Do you want to save your changes?"), new QMessageBox.StandardButtons( QMessageBox.StandardButton.Save, QMessageBox.StandardButton.Discard)); if (ret == QMessageBox.StandardButton.Save) { return saveFile("png"); } else if (ret == QMessageBox.StandardButton.Cancel) { return false; } } return true; }