java - JFrame getLocation and setLocation deal with system border differently -


i creating multi-user swing gui application, , want user's window location , size settings persist when log out , in. getting window location , size using getlocation() , getsize() methods on parent jframe when user logs out , saving them file, , when user logs in read values in , set window size , location using setlocation() , setsize().

the problem having getlocation() , getsize() appear subtracting off system border (e.g. if put window in upper left corner getlocation returns (1,54) instead of (0,0)), setlocation() , setsize() don't. result every time logout , log in, window appears offset , smaller did when closed it.

does know why might happening or how can around it? there other method should using , set window location , size?

i'm running java 1.7.0_45 on ubuntu 12.04, if helps.

thanks!

edit:

the following example replicates issue seeing:

import java.awt.dimension; import java.awt.eventqueue; import java.awt.point; import java.awt.event.actionevent; import java.awt.event.actionlistener;  import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.windowconstants;   public class jframetest {   private jframe frame;    private jbutton button;    private point lastlocation;   private dimension lastsize;    private void run()   {     button = new jbutton("test");     button.addactionlistener(listener);      lastlocation = new point(0, 0);     lastsize = new dimension(200, 200);      initframe();   }    private void initframe()   {     frame = new jframe();     frame.setdefaultcloseoperation(windowconstants.dispose_on_close);      frame.getcontentpane().add(button);      frame.setlocation(lastlocation);     frame.setpreferredsize(lastsize);      frame.pack();     frame.setvisible(true);   }    private actionlistener listener = new actionlistener()   {     @override     public void actionperformed(actionevent e)     {       if (e.getsource() == button)       {         lastlocation = frame.getlocationonscreen();         lastsize = frame.getsize();          frame.dispose();          initframe();       }     }   };    public static void main(string[] args)   {     eventqueue.invokelater(new runnable() {       public void run()       {         new jframetest().run();       }     });   } } 

also, see same issue when use getlocationonscreen() instead of getlocation().

you can use getlocationonscreen()

gets location of component in form of point specifying component's top-left corner in screen's coordinate space.


Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -