• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java awt setLocationRelativeTo with multiple monitors

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have Jpanel which is maximized on a button click. I do it by setting the dimensions to the screensize and then calling setLocationRelativeTo(null). This works fine if I have the panel in primary monitor, but when the panel is on other monitor the button click always makes the panel to move to primary monitor. Is there a way to get the currently used monitor of the panel and use the same for new location. Thanks in advance.

I have also posted this question in Stack overflow also.
http://stackoverflow.com/questions/13631335/java-awt-setlocationrelativeto-with-multiple-monitors-p

And I will make sure to edit the question, once I have the answer. Thanks for your time
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please BeForthrightWhenCrossPostingToOtherSites (link).

P.S. I'm on a roll this week catching crossposters!
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is, but you'd have to use GraphicsEnvironment, GraphicsDevice and GraphicsConfiguration. You'd need to find the GraphicsConfiguration object that best matches the location of the window.
 
Venki Umaashankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:There is, but you'd have to use GraphicsEnvironment, GraphicsDevice and GraphicsConfiguration. You'd need to find the GraphicsConfiguration object that best matches the location of the window.



Hi,
I have seen these links, but the problem is the window is shifting from one window to other on the button click. There is no issue if the Panel is in primary monitor already, since the button click moves the window to the primary monitor. To be more clear, I want to identity the monitor in which the panel is currently, user could move it between monitors. I want to find where it is currently and set the new location also to the same. Could some one please guide how this could be done using GraphicsConfiguration? I could not figure it out from the Javadocs. Thanks in advance.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GraphicsConfiguration has method getBounds() which returns the bounds of the matching screen. A window has method getBounds() which returns the bounds of the window. Likewise, you can calculate the bounds of any component by using getBounds() and then changing the top left corner to the result of getLocationOnScreen().

You then need to find which GraphicsConfiguration has a return value of getBounds() that best matches your window's or component's bounds. You should be careful that it's possible for a window or component to be on more than one screen.
 
Venki Umaashankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:GraphicsConfiguration has method getBounds() which returns the bounds of the matching screen. A window has method getBounds() which returns the bounds of the window. Likewise, you can calculate the bounds of any component by using getBounds() and then changing the top left corner to the result of getLocationOnScreen().

You then need to find which GraphicsConfiguration has a return value of getBounds() that best matches your window's or component's bounds. You should be careful that it's possible for a window or component to be on more than one screen.



Thanks Rob. Your suggestion and following this SO thread helped

http://stackoverflow.com/questions/1248386/how-do-i-determine-which-monitor-a-swing-mouse-event-occurs-in
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
reply
    Bookmark Topic Watch Topic
  • New Topic