• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is this for: setLocationRelativeTo()  RSS feed

 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as according to the question.

what is it for anyway?
i checked on the api of j2se1.5.0, it explained:
Sets the location of the window relative to the specified component. If the component is not currently showing, or c is null, the window is centered on the screen. If the bottom of the component is offscreen, the window is placed to the side of the Component that is closest to the center of the screen. So if the Component is on the right part of the screen, the Window is placed to its left, and visa versa.

so what is it means? cos i can't get the meaning. Anyone have the simple example to show me?

Regards
Nicky Eng
 
prashant gour
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this method set the location of dialog in respect of parent dialog.
and rest of the things are very much cleared in your question.


Prashant
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setLocationRelativeTo(null) is commonly used to center the gui on the screen.

much better than getting screen size then adding a formula for setLocation(int,int)

only 'gotcha' is the gui must have a size prior to calling setLocationRelativeTo(null),
either setSize(int,int) or pack(),otherwise the top-left corner of the gui
will be at the center
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see.

thank you very much.

so setLocationRelativeTo(null) is used to center frame in the screen.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!