This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying the window in the center of the MONITOR

 
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: 2703
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Rob Spoor
Sheriff
Posts: 20822
68
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: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
it's a teeny, tiny, wafer thin ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!