當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。