jTree.getX()+e.getX()
...

解决方案 »

  1.   

    e.getX()得到的是你捕获该鼠标事件的组件中的相对的位置,而jPopupMenu的显示是一个绝对作标。这就需要把捕获鼠标事件的组件的本身位置加上去。
    _________________________________________________________________
    java.awt.component.getX()getX
    public int getX()
    Returns the current x coordinate of the components origin. This method is preferable to writing component.getBounds().x, or component.getLocation().x because it doesn't cause any heap allocations. Returns:
    the current x coordinate of the components origin
    Since:
    1.2 ___________________________________________________________________
    java.awt.event.MouseEvent.getX()getX
    public int getX()
    Returns the horizontal x position of the event relative to the source component. Returns:
    x an integer indicating horizontal position relative to the component
      

  2.   

    楼上的说法好像不对吧? :)
    JPopupMenu.show()有个invoker参数 ,point是相对于它的 ,如果为null,才是绝对坐标。popUp.show(jTree, e.getX(), e.getY());
      

  3.   

    向 farawayzheng_necas(遥远) 学习:)如果用popup.show(this,x,y)这个时候,this是一个Applet或者。。,应该把invoker确定为弹出式菜单所要显示的组件。不过我自己的办法打到了效果,但是不专业哦。用: farawayzheng_necas(遥远) ( 说的方法:)
      

  4.   


    我也用过这个,挺好使的,你再查查this,看看API specification