当前位置: 首页>>代码示例>>Java>>正文


Java JPopupMenu.getSubElements方法代码示例

本文整理汇总了Java中javax.swing.JPopupMenu.getSubElements方法的典型用法代码示例。如果您正苦于以下问题:Java JPopupMenu.getSubElements方法的具体用法?Java JPopupMenu.getSubElements怎么用?Java JPopupMenu.getSubElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JPopupMenu的用法示例。


在下文中一共展示了JPopupMenu.getSubElements方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
 * Find relevant actions and call the factory to create a popup.
 */
private JPopupMenu createPopup(Point p) {
    int[] selRows = outline.getSelectedRows();
    ArrayList<Node> al = new ArrayList<Node> (selRows.length);
    for (int i = 0; i < selRows.length; i++) {
        Node n = getNodeFromRow(selRows[i]);
        if (n != null) {
            al.add(n);
        }
    }
    Node[] arr = al.toArray (new Node[al.size ()]);
    if (arr.length == 0) {
        if (manager.getRootContext() != null) {
            // display the context menu of the root node
            JPopupMenu popup = manager.getRootContext().getContextMenu();
            if (popup != null && popup.getSubElements().length > 0) {
                popupFactory.addNoFilterItem(outline, popup);
                return popup;
            }
        }
        // we'll have an empty popup
    }
    p = SwingUtilities.convertPoint(this, p, outline);
    int column = outline.columnAtPoint(p);
    int row = outline.rowAtPoint(p);
    return popupFactory.createPopupMenu(row, column, arr, outline);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:OutlineView.java

示例2: getPopupMenuArrayList

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/** Get PopupMenu and transfer it to ArrayList.
     * @param popup menu to be tranfered
     * @return transfered menu - !separator is ignored
     */
    public static ArrayList<NbMenuItem> getPopupMenuArrayList(JPopupMenu popup) {
        //System.out.print("getPopupMenuArrayList: "); popup.list(); //DEBUG
        MenuElement[] elements = popup.getSubElements();
        ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();

        for (MenuElement menuElement : elements) {
            //System.out.print("getPopupMenuArrayList: ");
//            ((JComponent) menuElement).list();
            if (menuElement instanceof JSeparator) {
                //System.out.println("adding separator");//DEBUG
                NbMenuItem separator = new NbMenuItem();
                separator.setSeparator(true);
                list.add(separator);
            } else {
                if (menuElement instanceof JMenu) {
                    NbMenuItem mitem = new NbMenuItem((JMenuItem) menuElement);
                    mitem.setName(mitem.getName());
                    mitem.setSubmenu (getMenuArrayList((JMenu) menuElement));
                    list.add(mitem);
                } else if (menuElement instanceof JMenuItem) //if()
                {
                    if (!((JMenuItem) menuElement).isVisible()) {
                        continue;
                    }
                    NbMenuItem item = new NbMenuItem((JMenuItem) menuElement);
                    item.setName(item.getName());
                    list.add(item);
                } else {
                    System.out.println("getPopup unknown:" + menuElement.toString());
                }
            }
        }
        return list;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:MenuChecker.java

示例3: createPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
void createPopup(int xpos, int ypos, boolean contextMenu) {
    if (manager == null) {
        return;
    }

    if (!popupAllowed) {
        return;
    }
    
    if (!isShowing()) {
        return;
    }

    JPopupMenu popup;

    if (contextMenu) {
        popup = Utilities.actionsToPopup(manager.getExploredContext().getActions(true), this);
    } else {
        Action[] actions = NodeOp.findActions(manager.getSelectedNodes());
        popup = Utilities.actionsToPopup(actions, this);
    }

    if ((popup != null) && (popup.getSubElements().length > 0)) {
        Point p = getViewport().getViewPosition();
        p.x = xpos - p.x;
        p.y = ypos - p.y;

        SwingUtilities.convertPointToScreen(p, ListView.this);

        Dimension popupSize = popup.getPreferredSize();
        Rectangle screenBounds = Utilities.getUsableScreenBounds(getGraphicsConfiguration());

        if ((p.x + popupSize.width) > (screenBounds.x + screenBounds.width)) {
            p.x = (screenBounds.x + screenBounds.width) - popupSize.width;
        }

        if ((p.y + popupSize.height) > (screenBounds.y + screenBounds.height)) {
            p.y = (screenBounds.y + screenBounds.height) - popupSize.height;
        }

        SwingUtilities.convertPointFromScreen(p, ListView.this);
        popup.show(this, p.x, p.y);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:ListView.java

示例4: createPopup

import javax.swing.JPopupMenu; //导入方法依赖的package包/类
private void createPopup(int xpos, int ypos, JPopupMenu popup) {
    if (popup.getSubElements().length > 0) {
        popup.show(TreeView.this, xpos, ypos);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:TreeView.java


注:本文中的javax.swing.JPopupMenu.getSubElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。