Can someone explane me what exactly happans here?
Sure. You're keeping the event dispatch thread tied up in an infinite loop, so it never gets to react to events such as "close window". Don't do that.
You should keep the event dispatch thread available for as much of the time as possible - don't perform any long-running tasks on it, including IO operations such as reading from files or the network.
See the "Concurrency in Swing" tutorial for more details.