Find the location/Position of JFrame in the window

我怕爱的太早我们不能终老 提交于 2019-12-18 20:12:08

问题


I am trying to find the Starting location/position of the JFrame in order to map the mouse cursor from the JFrame window to desktop. Is there anyway to find the X,Y position of JFrame ?


回答1:


You can use getLocation() or getLocationOnScreen() method of JFrame which are inherited from java.awt.Component.




回答2:


you have to implement the MouseListener Interface and call the override methods

public void mouseEntered(MouseEvent me) 

and use

MouseEvent.getX();

MouseEvent.getXOnScreen();



回答3:


Jframe.getX() // that will give you location of top left X coordinate of your jframe


Jframe.getY() // that will give you location of top left Y coordinate of your jframe


来源:https://stackoverflow.com/questions/7950726/find-the-location-position-of-jframe-in-the-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!