不是在窗口中位置。
通常getPoint()得到的都是相对窗口JFrame或者其它component的相对位置。
鼠标出了JFrame就不行。怎么得到在屏幕中位置

解决方案 »

  1.   

    getLocationOnScreen
    public Point getLocationOnScreen()Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space. Returns:
    an instance of Point representing the top-left corner of the component's bounds in the coordinate space of the screen 
    Throws: 
    IllegalComponentStateException - if the component is not showing on the screen
    See Also:
    setLocation(int, int), getLocation()
      

  2.   

    public void mousePressed(MouseEvent e) 
            {
                try{
                  JTree tree = (JTree)e.getSource();
                  int rowLocation = tree.getRowForLocation(e.getX(), e.getY());
                  TreePath treepath = tree.getPathForRow(rowLocation);
                  TreeNode treenode = (TreeNode) treepath.getLastPathComponent(); 
                  }catch(NullPointerException ne){
    }
            }
        }
      

  3.   

    public void mousePressed(MouseEvent e) 
            {
              int rowLocation = tree.getRowForLocation(e.getX(), e.getY());
            }
        }