This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
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?

wood burning stoves
subject: JFrame event order (maximize)
jQuery in Action, 3rd edition