本文整理汇总了Java中javax.swing.MenuSelectionManager.componentForPoint方法的典型用法代码示例。如果您正苦于以下问题:Java MenuSelectionManager.componentForPoint方法的具体用法?Java MenuSelectionManager.componentForPoint怎么用?Java MenuSelectionManager.componentForPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.MenuSelectionManager
的用法示例。
在下文中一共展示了MenuSelectionManager.componentForPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: menuDragMouseDragged
import javax.swing.MenuSelectionManager; //导入方法依赖的package包/类
/**
* This method is invoked when mouse is dragged over the menu item.
*
* @param e The MenuDragMouseEvent
*/
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
if (menuItem.isEnabled())
{
MenuSelectionManager manager = e.getMenuSelectionManager();
MenuElement path[] = e.getPath();
Point p = e.getPoint();
if(p.x >= 0 && p.x < menuItem.getWidth()
&& p.y >= 0 && p.y < menuItem.getHeight())
{
JMenu menu = (JMenu) menuItem;
MenuElement[] selectedPath = manager.getSelectedPath();
if(! (selectedPath.length > 0
&& selectedPath[selectedPath.length-1]
== menu.getPopupMenu()))
{
if(menu.isTopLevelMenu() || menu.getDelay() == 0
|| e.getID() == MouseEvent.MOUSE_DRAGGED)
{
MenuElement[] newPath = new MenuElement[path.length + 1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length] = menu.getPopupMenu();
manager.setSelectedPath(newPath);
}
else
{
manager.setSelectedPath(path);
setupPostTimer(menu);
}
}
}
else if (e.getID() == MouseEvent.MOUSE_RELEASED)
{
Component comp = manager.componentForPoint(e.getComponent(),
e.getPoint());
if (comp == null)
manager.clearSelectedPath();
}
}
}