You can call Window#setFinished(true) to terminate the loop