File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 10372
    
    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: 19693
    
  20

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 ?