Remembering Window State

Various threads have addressed parts of this topic, but I haven't seen a complete workable solution so far. Here's the problem:
When my application starts, it's supposed to restore its main window (a JFrame) to the state it had when it was last closed (unless it was minimized). If it was maximized, it should maximize automatically, otherwise it should open with the same location & dimensions it last had. As the application runs, I monitor changes in size, location & maximized state, then save them to a properties file when it exits.
Mostly, this is working OK, but I'm having a problem the ComponentListener. When the user maximizes the window, the componentMoved method is called, but at that point the Frame state doesn't indicate the window is maximized. So I save the window coordinates, but they turn out to the wrong coordinates, because the window is maximized. Here's my componentMoved method:
* Saves new position when frame moves.
* @param event The event being handled.
public void componentMoved(ComponentEvent event)
   Object source = event.getSource();
   if (source instanceof UprrFrame)
      UprrFrame frame = (UprrFrame)source;
      if (frame.isMaximized() == false)
         frame.saveBounds();
}The frame.IsMaximized method looks like this:
* Determines whether the frame is currently maximized.
* @return <b><code>True</code></b> if maximized.
public boolean isMaximized()
   int state = getExtendedState();
   boolean maximized = (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH;
   return maximized;
}I'm, not sure if I'm doing something wrong, or whether I've stumbled across an AWT/Swing bug. Any insights would be greatly appreciated!
P.S. I'm running JDK 1.4 under Windows XP.

If your solution works for you, then thats all good. However, i'll add this for completion...
Actually, the invokeLater in componentMoved does not always work in this case... it might seem to work all the time, but in reality, it's just luck that it's working. If you test it in enough environments, or with slower machines, you'll see what I mean.
Basically, you are trying to time it so that the test for frame maximization occurs after the window state change event. However, the window state change events are caused by asynchronous native window events.. and if the machine is slow enough (or perhaps fast enough), the invoke later is executed too sonn, and it says the frame is not maximized when it is.
You need to save the window location in componentResized, and rollback the save transaction when you hear a window state changed event from NORMAL -> BOTH_MAXIMIZED.

Similar Messages

  • [SOLVED]KDE does not remember window state, restoring from System Tray

    Hi,
    I'm facing a problem with some KDE applications that dock in the system tray, like Amarok and Konversation. I like to keep these apps maximized. But when I restore them from the system tray, they always revert back to their original, unmaximized size. Is there any workaround or fix for this?
    Using KDE 4.3.4-2 (not KDEmod)
    Thanks.
    Last edited by codemon (2009-12-08 08:56:16)

    Funny thing happened. I tried out your suggestion for my Firefox window, which would always start in an un-maximized state. It worked perfectly. Then I opened up Konversation and Amarok, and found that they properly remember the window state now!
    Thanks for the help.

  • Gnome 3 - Remember window state

    Hi fellows. I've been using gnome3 for a while now. One thing i couldn't figure out is how to make it remember the window state (maximized, unmaximized). For example, if i open a terminal, maximize it and then close it, i want the therminal maximized next time i open it. That doesn't happen and the terminal opens unmaximized again.
    Is there a way to do that in gnome3? Thanks!

    I'm fairly positive that Compiz is incompatible with Mutter in GNOME 3.  If you insist on having Compiz then the Xfce desktop environment paired with compiz-manjaro from the AUR works perfectly on the 3 machines I run it on.  Xfce is a light-weight desktop and is similar to GNOME 2.  A bit of tweaking here and there and it's sexy too.

  • My setup: iMac hardline to Canon i960 printer. Issue: endless printing of the same document. The printer window states that the pinter is in use and there is nothing listed in the Print Queue.  How can I stop printing the document?

    My setup: iMac hardline to Canon i960 printer. Issue: endless printing of the same document. The printer window states that the pinter is in use and there is nothing listed in the Print Queue.  How can I stop printing the document?

    Soution: Delete the printer and add the same printer back in, therefore creating a new print queue.

  • Invalid request for a change in window state

    Ok...
    Creating a JSR168 portlet and it works fine in Pluto, but I get the following when I deploy to P7:
    ERROR: Content not available. REASONE: Invalid request for a change in window state
    Here is what the portlet is supposed to do:
    * Display a form
    * User clicks find
    * Lookup is performed
    * Window state in processAction() method of portlet is changed to MAXIMIZED
    * I'm guessing this is where the error is occuring
    I also think that for the TableContainer, I have some sort of attribute incorrect having to do with one of the channelsIs values.
    I tried toggling them one way or another without any effect.
    Suggestions?

    Ive run into this issue also. I need a way for a portlet to change to its maximized state for the purposes of user registration. Is there anyway this can be done? I know that sun jsp "Providers" which are shown on their example desktop, have some sort of maximized state that they can go into, but im not sure how to use this in a portlet.
    There seems to be very inconsistent support between the proprietary sun provider api, and the portlet api.

  • InDesign won't remember window location

    I'm running InDesign CS3 on a Windows XP system with Service Pack 2.
    InDesign and InCopy open maximized, and I want them to open at half-screen so I can work in them side by side. I've saved workspaces, but that doesn't seem to work.

    I'm similarly annoyed by the application's apparent inehrent inability to remember window size / configuration / placement on desktop whensuccessively opening the app.
    In particular, Win 7 (64-bit FWIW in this instance) and using InDesign CS6, v8.0.1
    After creating a shortcut on the desktop, the only options afforded through its Properties, at least as far as I've found, are to Run: Normal Window / Minimized / Maximized. Both Minimized and Maximized work as advertised, but Normal Window isn't behaving like a "normal" window, at least normal in the context of most applications running on Windows.
    Is there anyway to get InDesign to remember these settings?
    Thank you very much.
    Kelly

  • Mail Not Remembering Window Position of Previous Session (again)

    Everytime I relaunch Mail, I have to rearrange the viewer windows to the way that is most efficient to use them. Is there a way for Mail to remember window positions, and sort preferences for each viewer window?

    Interestingly, Mail does seem to remember the window positions, in its com.apple.Mail.plist, but it isn't applying the remembered positions. I tried a few times, and on at least one try it got the positions correct. Could it be that if you quit, restart then quit and restart again it will have them right on the second restart?
    AK

  • How to force Adobe Reader to remember window size

    Hi
    I need Adobe Reader to remember window size and placement. I work on a remote desktop enlarged into two screens and i need Adobe Reader to open on one of them, but default settings open window in the middle of the screen so half of window is one one screen and half is on second one...
    Is there a way to do it?
    Thanks

    There are now some answers in http://forums.adobe.com/thread/797451

  • Running a  oracle report 6i  with maximized window state

    hi
    how can i run a report with maximized window state.
    sincerely
    rajesh

    Use MAXIMIZE=Yes on the command line.

  • Some programs won't remember window size and position

    I have a couple programs, notably ComicNerd, that won't ever seems to remember window size or position from quit to restart. I can't seems to find any evidence other people are having the same problem with the program, so I assume it's something wrong with my computer. Anyone have any idea how I can fix this? Is there some permissions problem or something?

    It's likely a corrupted Preference file
    Look in your Users/Library/Preferences folder for  .plist file with ComicNerd in it and just move it to your desktop and restart the program/computer.
    The preference file should rebuild itself, so look for it and if it's in the Preference folder then delete the one on the  desktop.
    You also might want to run ALL the cleaning and maintenance aspects of the free OnyX and reboot.
    http://www.titanium.free.fr/
    the Verify > preference (show only corrupted) should also help locate other corrupted .plist (Preference) files for similar action like you did above.

  • Animation Window state save is inconsistent

    Photoshop 10-E does not consistently save the state of the animation window. Often it opens in Timeline mode, which means I have to set it to Frames mode, change the loop mode, and change the default frame timing, before I can even start work. I'm guessing that it's designed to save state because it does so about half the time. This is not a big issue but it's annoying and it's just one of many small annoyances that are making this version a pain in the *** to use.
    I've tried saving a workspace but it doesn't appear to save the state of the animation window, at least not consistently.
    Any suggestions about how to fix this?

    If your solution works for you, then thats all good. However, i'll add this for completion...
    Actually, the invokeLater in componentMoved does not always work in this case... it might seem to work all the time, but in reality, it's just luck that it's working. If you test it in enough environments, or with slower machines, you'll see what I mean.
    Basically, you are trying to time it so that the test for frame maximization occurs after the window state change event. However, the window state change events are caused by asynchronous native window events.. and if the machine is slow enough (or perhaps fast enough), the invoke later is executed too sonn, and it says the frame is not maximized when it is.
    You need to save the window location in componentResized, and rollback the save transaction when you hear a window state changed event from NORMAL -> BOTH_MAXIMIZED.

  • How to keep first form window state maximize when you called the second for

    HI,
    how to keep first form window state maximize when you called the second form ?
    Thanks

    Here is sample of doing this.
    Chris

  • How to get one persisting windows state?

    Hi gurus,
    I'm new in JAVA ,I want to develop an application that initiates a single window as principal in the Windows task bar and other windows are as "daughters" of this, doing some tests I can not get, I open a second window generates a second application in Windows taskbar. I do not know if the term " persisting windows state" is related to this topic. I'm using NetBeans 6.8
    regadrs
    Mexman

    Thanks! I am surprised the problem was the NTFS format. I can't understand why Mac doesn't support this format (anymore). And after reading about the problem and trying some solutions, I formatted the partition to FAT32 and now it works well. Regards!

  • Lasr week I downloaded the latest OS update for my iPhone 5S. Now, a popup window states the password is invalid for voicemail. I have never need a password or I don't need one or want one. Have searched is setup to find a way to turnoff. Help!

    Last week I downloaded the latest OS update for my iPhone 5S. Now, a popup window states the password is invalid for voicemail. I have never needed a password or I don't need one or want one. Have searched is setup to find a way to turnoff the required password. Phone has been like this since the update to the OS.

    ka4txy wrote:
    Last week I downloaded the latest OS update for my iPhone 5S. Now, a popup window states the password is invalid for voicemail. I have never needed a password or I don't need one or want one. Have searched is setup to find a way to turnoff the required password. Phone has been like this since the update to the OS.
    If you are getting a voicemail password prompt, that usually means you have a voicemail.  In order to hear it you will need to enter the passcode, it only needs to be entered once.
    To reset your passcode, call your service provider.

  • Flash Player remember window position after exit?

    How about make the Flash Player remember window position after exit?  So that it opens in our preferred position everytime?

    These are user-to-user forums.  If your suggestion is meant as a possible product improvement, use...
    Adobe - Wishlist & Bug Report
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

Maybe you are looking for

  • How do I filter two columns of names to see What names are the same?

    I have two lists of names (one with 2,000+ names and one with 300+ names) I want make a column that shows the names that are not in both columns and the names that are. Is there an automated way of doing this? Basically, I have 2,000 friends on faceb

  • ColdFusion MX7 Error When Starting Apache2Triad

    I just installed the ColdFusion MX7 trial on my local machine. When I try to start the Apache2Triad (uses Apache 2.2.0) service it fails to start and the following error is written to the system log file: quote: The Apache service named Apache2Triad

  • Pages won't sort alfabetically

    Hello, I made a tabel with 5 colums. I want to sort all content alfabetically. First colum starting with A and last one stopping with Z. For some reason, I can only sort ONE colum = meaning tis colum is sorted correctly. When i go to the next colum a

  • Designer Repository meta-model

    The elements that make up the Designer Repository are fully documented at http://technet.oracle.com/docs/products/designer/doc_library/6i_release42/CDOC72/api/index.htm but does anyone know where I could find the same information in diagram form i.e.

  • Why does "open all in tabs" delete my entire current browsing session?

    I went into my bookmarks and selected "open all in tabs" for a particular folder. It opened all those links in new tabs, all right - but it closed every tab I already had open, and did not save the session. It is really, massively frustrating and str