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