如何获取 Swing 元素的屏幕位置?

2022-09-01 13:59:37

如何获取元素的实际屏幕位置,例如按钮?如果我使用getBounds,我会获得相对于父容器的位置,而不是屏幕...


答案 2

你可以试试这个:

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

推荐