1

I have a JFrame I switch being displayed between two monitors. The monitor on the left (Windows sees it as display 2) has a resolution of 1920x1080 and my code to move the JFrame is:

setLocation(0,0)
setSize(1920, 1080)

and this works just fine with the frame perfectly center on the monitor. However on the right monitor (Windows sees it as display 1) it has a resolution of 1600x900 and the code for that is:

setLocation(1920,74)
setSize(1600, 900)

and I have to have the '74' in there otherwise the frame will not fit perfectly in the monitor. If I do setLocation(1920,0) part of the frame is missing on the top of the monitor. My question is what(why?) exactly is the number 74 and how do I calculate it for other resolutions?

MisterXero
  • 1,098
  • 2
  • 9
  • 17
  • Can you access Windows monitor properties with Java? (Which would be not-portable. Then again, neither is your code on any other system than yours ) See `rcMonitor` on http://msdn.microsoft.com/en-us/library/dd145066(v=vs.85).aspx – Jongware Apr 24 '14 at 19:08
  • Artur answer from below is the solution. For this project I am not worried about portability. – MisterXero Apr 24 '14 at 19:11
  • 1
    You can use GraphicsEnvironment, see these [answers](http://stackoverflow.com/questions/4627553/java-show-jframe-in-a-specific-screen-in-dual-monitor-configuration). 74 comes from the "free area" without a 26 pixel toolbar 1000 - 74 - 26 = 900. – Joop Eggen Apr 24 '14 at 19:15
  • Voted up because this question (and the correct answer) might be useful for future reference. – eivamu Apr 24 '14 at 19:38

1 Answers1

3

It is not a Java issue - you just need to perfectly align displays in Windows Display Properties :).

Artur Malinowski
  • 1,124
  • 10
  • 30