本文整理匯總了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();
}
}
}