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
没试过,不知道行不行:)
其中的1,1就是你自己想确定的头部的位置的坐标
看看tabbedPane的头部,多高,可能22左右
然后,在鼠标事件中,
if(e.getY()<=22)
popup.show(jtabbedpane,e.getX(),e.getY());
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
那么鼠标右键时,应该是只能捕捉到在标签的右键
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());
}
}
}