RT,或者如何获取JFrame中一个组件的绝对坐标

解决方案 »

  1.   

    getContentPane()能获取除了标题和边框之外的区域,由些应该可以近似计算得到Frame的宽度吧。
      

  2.   

    JFrmae.getLocation();//获得JFrmae在屏幕上位置
    JButton.getX(),JButton.getY();//获得JButton相对JFrame位置
    JButton.getLocationOnScreen();//获得JButton在屏幕上的位置
    JFrame标题栏宽度 = JButton.getLocationOnScreen().y - JFrmae.getLocation().y - JButton.getY();
    应该是30个像素