Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Always centering frame through a BaseFrame overiding setVisible: dirty ?

 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Norbert Lebenthal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do so now, in the subclasses' constructors:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic