100分送上。

解决方案 »

  1.   

    show的时候不是可以指定位置吗,你先判断这个坐标是不是位于头部,如果是就show,否则就不show了。
    没试过,不知道行不行:)
      

  2.   

    首先你用JTabbedPane.add(popmenu);然后,popmenu.show(JTabbedPane,1,1)
    其中的1,1就是你自己想确定的头部的位置的坐标
      

  3.   

    楼上的,你没有明白我的意思,我是说,当鼠标落在JTabbedPane的头部(切换卡)的时候,popmenu才被显示,象JBuilder那样。而不是让它显示在1,1坐标上!现在的问题是,我如何判断鼠标是落在JTabbedPane的头部(切换卡)上?
      

  4.   

    给个笨方法:
    看看tabbedPane的头部,多高,可能22左右
    然后,在鼠标事件中,
    if(e.getY()<=22)
     popup.show(jtabbedpane,e.getX(),e.getY());
      

  5.   

    呵呵,这个方法也够笨的了!!那假如tabbedpane有好几十个选项卡,分为n层呢?
      

  6.   

    indexAtLocation public int indexAtLocation(int x,int y)Returns the tab index corresponding to the tab whose bounds intersect the specified location. Returns -1 if no tab intersects the location. Parameters:
    x - the x location relative to this tabbedpane
    y - the y location relative to this tabbedpane 
    Returns:
    the tab index which intersects the location, or -1 if no tab intersects the location
    Since: 
    1.4 
      

  7.   

    呵呵 搞笑在JTabbedJPane的面板区加入一个JPane
    那么鼠标右键时,应该是只能捕捉到在标签的右键
      

  8.   

    吾来试试 ~  搞定
    public void mouseReleased(MouseEvent e) {

    //返回此鼠标事件是否为该平台的弹出菜单触发事件。
    if(e.isPopupTrigger()) {

    //只在选项卡上显示鼠标右键的提示
    //在相对于初始组件的 x、y 位置上显示弹出式菜单。
    int i = tabbedPane.indexAtLocation(e.getX(), e.getY());
    if(i != -1) {
    tabbedPane.setSelectedIndex(i);
    m_tab_popup.show(tabbedPane, e.getX(), e.getY());
    }
    }

    }