Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

setLocationRelativeTo

Thread view: 
Allan Valeriano - 22 Feb 2007 13:54 GMT
Hi all,

I have a class that extends JFrame, and on its constructor, I have the
2 lines of code:

pack();
setLocationRelativeTo(owner);

I'd like to know what would be the difference if I swap those 2
lines...
It seems that if I use:

setLocationRelativeTo(owner);
pack();

the frame gets wrongly aligned but if I put the pack before
setLocationRelativeTo, it gets perfectly centered with the mother
window.
Does anybody knows what is the difference for java when I swap those
lines?

thanks in advance
Allan Valeriano
Andrew Thompson - 22 Feb 2007 14:12 GMT
> Hi all,
>
[quoted text clipped - 14 lines]
> setLocationRelativeTo, it gets perfectly centered with the mother
> window.

Given that pack()..
"Causes this Window to be sized to fit
the preferred size and layouts of its
subcomponents. "
..I consider your result unsurprising.

I would generally pack() a frame before
it is setVisible(true), let alone before
attempting to set its location.

> Does anybody knows what is the difference for java when I swap those
> lines?

One works as advertised, the other is
expected (by my reading of the JavaDocs)
to produce unsatisfactory results.

Call pack() first, then the setLocationRelativeTo
method can have a good idea how big the (J)Frame
needs to be (and 'centering' it based on the
position of other components becomes anything
more than guesswork).

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.