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


Java JMenuBar.getMenu方法代码示例

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


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

示例1: altPressed

import javax.swing.JMenuBar; //导入方法依赖的package包/类
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:WindowsRootPaneUI.java

示例2: getMenu

import javax.swing.JMenuBar; //导入方法依赖的package包/类
/**
 * Finds the top-level menu named s.
 *
 * @param s the text of the menu. If null, returns null.
 * @return the menu, if there is one, or null if not found.
 */
public JMenu getMenu(String s) {
    if (s == null) {
        return null;
    }
    JMenuBar b = getJMenuBar();
    int n = b.getMenuCount();
    for (int i = 0; i < n; i++) {
        JMenu m = b.getMenu(i);
        if (m.getText().equals(s)) {
            return m;
        }
    }
    return null;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:21,代码来源:AEViewer.java

示例3: getHelpMenu

import javax.swing.JMenuBar; //导入方法依赖的package包/类
public JMenu getHelpMenu() {
  final JMenuBar mb = MenuManager.getInstance().getMenuBarFor(
    GameModule.getGameModule().getFrame());

  return mb.getMenu(mb.getMenuCount()-1);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:7,代码来源:Documentation.java

示例4: altReleased

import javax.swing.JMenuBar; //导入方法依赖的package包/类
void altReleased(KeyEvent ev) {
    if (menuCanceledOnPress) {
        WindowsLookAndFeel.setMnemonicHidden(true);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        return;
    }

    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    if (msm.getSelectedPath().length == 0) {
        // if no menu is active, we try activating the menubar

        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;

        // It might happen that the altRelease event is processed
        // with a reasonable delay since it has been generated.
        // Here we check the last deactivation time of the containing
        // window. If this time appears to be greater than the altRelease
        // event time the event is skipped to avoid unexpected menu
        // activation. See 7121442.
        // Also we must ensure that original source of key event belongs
        // to the same window object as winAncestor. See 8001633.
        boolean skip = false;
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            Component originalSource = AWTAccessor.getKeyEventAccessor()
                    .getOriginalSource(ev);
            skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
                    ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
        }

        if (menu != null && !skip) {
            MenuElement[] path = new MenuElement[2];
            path[0] = mbar;
            path[1] = menu;
            msm.setSelectedPath(path);
        } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    } else {
        if((msm.getSelectedPath())[0] instanceof ComboPopup) {
            WindowsLookAndFeel.setMnemonicHidden(true);
            WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        }
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:WindowsRootPaneUI.java


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