• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying the window in the center of the MONITOR  RSS feed

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to display my software window in the center of the minotor, because right now it is appearing at the top left. This is what I have tried



this code at least brought that to bit center but you know this is not the best way. I tried putting 0 and 0 as values for the setLocation() method, but no good. Please help..
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Posts: 20897
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob's code will center the window in the available area. This excludes space occupied by the task bar and windows that are docked at one of the sides.

To center a window in the center of the entire screen, you must center it in the current screen bounds:
The calculation of x and y takes the center of the screen (screenSize.width / 2, screenSize.height / 2), and subtracts the relative center of the frame (frameSize.width / 2, frameSize.height / 2).
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent, Perfect, Great and Amazing!!! Thanks both of you for the valuable help!! Thanks a lot!!
 
Rob Spoor
Sheriff
Posts: 20897
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!