View Full Version : Desktop: close and minimize window events

17 Jul 2009, 5:40 AM

I am using Desktop API.

How can I distinguish between window closing (x) and minimize events (_) if they both fire Events.Hide ?

I need to release some resources if window is closed (i.e. removed from desktop) and i don't need to release them if it is just minimized.

Thanks in advance!

23 Jul 2009, 8:29 AM
i have the same problem and I solve like below:

every new Window, I add a Listener to get the Event.Hide. the Listener Know your Window
The trick is when i got the event.hide, i saw if the Window is minimized... if not, is because the "close" events was called...so, you get the desktop and remove that window

public class MyWindow extends Window{

public MyWindow () {

this.setSize("98%", "98%");

// add the listener
this.addListener(Events.Hide, new ListenerCloseWindow(this));

public class ListenerCloseWindow extends WindowListener{

private MyWindow myWindow;

public ListenerCloseWindow(MyWindow myWindow) {
this. myWindow = myWindow;


public void handleEvent(WindowEvent e) {
EventType type = e.getType();

if (type == Events.Hide){
//get the Desktop Manager
Desktop desktop =AplicacaoRoot.getInstance().getDesktop();

// if not is minimize, remove the window from the Windows List
if(myWindow.getData("minimize") == null)




23 Jul 2009, 10:43 PM
Thanks, brunonandolpho!

I thought that when window is closed it is removed from desktop and garbage collected. As I see now I was wrong.
Is it true that I must always listen to close event and call desktop.removeWindow(window) manually?

24 Jul 2009, 7:34 AM
It is true that the window is not removed from the desktop list windows when the hide event is fired...so, I call desktop.removeWindow(window) manually to remove that..I put that because in my application, i migrate from 1.2.4 to 2.0...and in 1.2.4 the evenst.close works...
so, if i want the same stuff from my application in v 2.0, i need to call deskto.removeWindow to complete the action of Desktop class...