Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #231

Re: Saving Windows Positi

From "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this>
Subject Re: Saving Windows Positi
Message-ID <1164739443.531978.166660@l39g2000cwd.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
References <1164725907.621312.39690@80g2000cwy.googlegroups.com>
Date 2011-04-27 15:26 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui


On Nov 28, 9:58 am, "Jason Cavett" <jason.cav...@gmail.com> wrote:
> I'm writing a program in which I want to save information like window
> size, window position, is it maximized, etc.  I have it (mostly)
> working, but I've noticed one bug that's been annoying me, and I'm not
> entirely sure how to fix it.
>
> If the application window is maximized when I leave the application, it
> saves the previous size and position (before the maximization) to an
> XML file.
>
> The problem is, when I start the application the next time, it is
> maximized.  That's good.  When I click the button to "unmaximize" it,
> it doesn't always return to the original size and position (which I
> have saved).  Sometimes it will be placed at position -4, -4 (the upper
> left corner of the screen).
>
> The only thing I can think of is that, because I am firing two
> listeners (I'm watching for component resized and component moved)
> something isn't registering correctly.  Here's the portion of my code
> that is performing the actual resizing.  (It gets called twice if I
> perform a maximize because Java sees a maximization as both a resize
> and a position change.)
>
>         private void maximize() {
>                 if (view.getExtendedState() != JFrame.MAXIMIZED_BOTH
>                                 && config.isMaximized()) {
>                         config.setMaximized(false);
>                         this.setLocation(config.getWindowPosition());
>                         this.setSize(config.getWindowSize());
>                 } else if (view.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
>                         config.setMaximized(true);
>                 } else {
>                         config.setWindowPosition(this.getLocation());
>                         config.setWindowSize(this.getSize());
>                 }
>          }
>
> Any suggestions would be appreciated.  If I'm doing this entirely
> wrong, I'd appreciate knowing that as well.  Thanks!

I figured out what I was doing wrong, and in case anybody was
wondering, there are two issues here.

First of all, I should not have been using the ComponentListener to
monitor state change.  I didn't realize that JFrames had a
WindowStateListener.  However, my code would have still worked.

The other issue I didn't realize is that, in order for a window to go
from maximized state to it's "normal" state, it had to have a previous
size and location already set for it to revert to.  Unfortunately, I
was completely ignoring the fact that I needed to set it's previous
size and location when I created the view from the config file.

...it's always the stupid errors...  :-p

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar


Thread

Saving Windows Position/S "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
  Re: Saving Windows Positi "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000

csiph-web