This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Always centering frame through a BaseFrame overiding setVisible: dirty ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Always centering frame through a BaseFrame overiding setVisible: dirty ?" Watch "Always centering frame through a BaseFrame overiding setVisible: dirty ?" New topic
Author

Always centering frame through a BaseFrame overiding setVisible: dirty ?

Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
hi

In my application, I use all over the place a BaseFrame, to set up common stuff for all frames.

Among the common stuff, I would like to center the frame.

I ended up doing it this way:


is it utterly dirty or is it ok ?

thanks in advance
best
norbert
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Why do you need to override setVisible() and have a center() method? You can always put the line setLocationRelativeTo(null) in your constructor and it would still work.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

If the frame is hidden, then shown again, it is centered again. That can be annoying or useful, depending on the situation. I wouldn't do this but let the calling method center the frame as needed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
in fact when it was set first in the BaseFrame constructor, the window wasn't centered: the upper left corner was at the center of the screen.

but I agree that it could be called in the sub classes, way more explicit

thks !
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
I do so now, in the subclasses' constructors:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Always centering frame through a BaseFrame overiding setVisible: dirty ?
 
Similar Threads
awt - what does pack( ) do here?
final and layout
JInternal frame little (or not) problem
class-file not executing
Using JPanel to create JTabbedPane