使 x0 和 y0 从 jframe 的中心开始?
making x0 and y0 start from center in jframe?
您好,我只是想知道如何在不使用 frame.setLocationRelativeTo(null)
的情况下使 x 轴和 y 轴从 jframe 的中心开始,因为我希望能够让 jframe 跟随我的光标,对吧现在它将 jframe 的左上角放在我的光标上,但我希望它位于中心。
谢谢
这很容易
int newX=cursorX-frame.getWidth()/2;
int newY=cursorY-frame.getHeight()/2;
优于
frame.setLocation(newX,newY);
这将以鼠标光标位于框架中间的方式定位框架。
您好,我只是想知道如何在不使用 frame.setLocationRelativeTo(null)
的情况下使 x 轴和 y 轴从 jframe 的中心开始,因为我希望能够让 jframe 跟随我的光标,对吧现在它将 jframe 的左上角放在我的光标上,但我希望它位于中心。
谢谢
这很容易
int newX=cursorX-frame.getWidth()/2;
int newY=cursorY-frame.getHeight()/2;
优于
frame.setLocation(newX,newY);
这将以鼠标光标位于框架中间的方式定位框架。