File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JFrame event order (maximize) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame event order (maximize)" Watch "JFrame event order (maximize)" New topic

JFrame event order (maximize)

David Nemeskey
Ranch Hand

Joined: Nov 08, 2006
Posts: 52

I have a problem regarding the order of JFrame events.

I am using a frame, which can be closed. I want to achieve that on next reopening, it appears in the same place and in the same size as it was before it was closed. So I save its state, location and size.

The problem is the next: if it was maximized when it was closed, how can I save the non-maximized bounds? I managed to do it with the size, but I find it difficult for location. Why? It is because the order I receive the events:
1. Move (ComponentListener.componentMoved)
2. Maximize (WindowStateListener.windowStateChanged)
3. Resize (ComponentListener.componentResized)

So I can check in resize if the frame is maximized, and if not, I do not save the new size. However, move comes before maximize, so that does not work here. Two question comes to mind:
1. Why isn't the maximized event the first ("cause" of the others), or the last (the "consequence")? It doesn't really make sense...
2. Is the above order fixed across platforms, LaFs, etc? Because I can make a solution for this order, but if under say, Linux (the above was observed on Windows), the order is different, I am beat.

Or is there some other way to save the problem?

I agree. Here's the link:
subject: JFrame event order (maximize)
It's not a secret anymore!