• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

centering a dialog

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in Swing (by Robinson) and in this sun tutorial its claimed:

If you specify a Frame or Dialog, then the Dialog will appear over the center of the Frame (...). If you specify a component inside a Frame, then the Dialog will appear over the center of that component (...). If you specify null, then the look and feel will pick an appropriate position for the dialog — generally the center of the screen (...).


the example i show bellow infirms that:
case A:
frame isnt centered - either using new JFrame() or null the dialog pops up centered relative to screen
case B:
frame is centered - in both cases dialog appears centered relative to screen, as above

my conclusion: dialog allways centers itself relative to screen
what am i missing here?

the code:
 
Rancher
Posts: 3051
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In none of you examples did you actually specify a visble component.

"null" is not a visible component.
"new JFrame()" is not a visible component.
 
Sheriff
Posts: 21759
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

miguel lisboa wrote:


Check out Window's setLocationRelativeTo method. If you pass null as its argument it will center the window (JFrame is a Window subclass) on the screen taking into account things like the task bar etc.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Camick wrote:In none of you examples did you actually specify a visble component.

"null" is not a visible component.
"new JFrame()" is not a visible component.


case solved!

thanks to both
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!