Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

having JFrame show up in the active screen where the mouse cursor is  RSS feed

 
Samson Chung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am getting a bit annoyed after I have setup the multiple screen display system (three screens) and am wondering if anyone can help me with this.

My primary IDE is netbeans 8 and my primary screen is the one on my laptop (I don't want to change this) where as my primary IDE screen is one of the two external monitors.

Everytime I run the GUI programs, my program would go back to my primary display on the laptop and center itself. I am wondering if there is a way to have the program pick up where the mouse cursor is and send the GUI to that monitor instead?

This gets really annoying as the all popups goes back to the primary monitor as well, if there is a way to set that to the active screen, that'd be great too.

Thanks
 
Samson Chung
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I have put together so far... it works 60% of the time but not 100% fool proof.

Point mPoint = MouseInfo.getPointerInfo().getLocation();
mPoint.x = mPoint.x - (widthOfJFrame /2);
if (mPoint.x < 0) {
mPoint.x = 0;
}
mPoint.y = mPoint.y - (heightOfJFrame / 2);
if ((mPoint.y < 0)) {
mPoint.y = 0;
}

prg.setLocation(mPoint);

This will set the JFrame in relative to the cursor's location on screen, but it doesn't work properly if the cursor is on the left side of the primary screen. Any suggestions to make this more fool proof?

I am looking at GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(), but it doesn't really give me the location in relative terms to the default screen, if there is a way, please do share
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!