How to get screen position of a Swing element?

Viewed 28011

how do I get the actual screen position of an element, say a Button? If I use getBounds I get the position relative to the parent container, not the screen...

2 Answers

You can try this:

// Convert a coordinate relative to a component's bounds to screen coordinates 
Point pt = new Point(component.getLocation()); 
SwingUtilities.convertPointToScreen(pt, component); 
Related