Java Code Examples for javax.swing.JMenuBar#getMenu()
The following examples show how to use
javax.swing.JMenuBar#getMenu() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowMenu.java From pumpernickel with MIT License | 6 votes |
/** * On Mac often the menus won't really update without this hack-ish twist: * remove the menu and re-add it. Voila! It's both unnecessary and crucial * at the same time. * * @param f * the frame whose menubar you need to update. * @param menu * the menu you need to update. */ static void fixMenuBar(JFrame f, JMenu menu) { JMenuBar mb = f.getJMenuBar(); if (mb != null) { JMenu[] menus = new JMenu[mb.getMenuCount()]; for (int a = 0; a < menus.length; a++) { menus[a] = mb.getMenu(a); } boolean found = false; List<JMenu> menusToAdd = new ArrayList<>(); for (int a = 0; a < menus.length; a++) { if (menus[a] == menu) found = true; if (found) { mb.remove(menus[a]); menusToAdd.add(menus[a]); } } for (JMenu menuToAdd : menusToAdd) { mb.add(menuToAdd); } } }
Example 2
Source File: OSPFrame.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Gets a menu with the given name from the menu bar. Returns null if menu item does not exist. * * @param menuName String * @return JMenu */ public JMenu getMenu(String menuName) { JMenuBar menuBar = getJMenuBar(); if(menuBar==null) { return null; } menuName = menuName.trim(); JMenu menu = null; for(int i = 0; i<menuBar.getMenuCount(); i++) { JMenu next = menuBar.getMenu(i); if(next.getText().trim().equals(menuName)) { menu = next; break; } } return menu; }
Example 3
Source File: WindowsRootPaneUI.java From hottub with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 4
Source File: WindowsRootPaneUI.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 5
Source File: WindowsRootPaneUI.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 6
Source File: WindowsRootPaneUI.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 7
Source File: WindowsRootPaneUI.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 8
Source File: UIUtils.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public static int findMenuPosition(JMenuBar menuBar, String name) { int n = menuBar.getMenuCount(); for (int i = 0; i < n; i++) { JMenu menu = menuBar.getMenu(i); if (name.equals(menu.getName())) { return i; } } return -1; }
Example 9
Source File: WindowsRootPaneUI.java From JDKSourceCode1.8 with MIT License | 5 votes |
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(); } } }
Example 10
Source File: WindowsRootPaneUI.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 11
Source File: WindowsRootPaneUI.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 12
Source File: WindowsRootPaneUI.java From JDKSourceCode1.8 with MIT License | 4 votes |
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); } } }
Example 13
Source File: WindowsRootPaneUI.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 14
Source File: WindowsRootPaneUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 15
Source File: WindowsRootPaneUI.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 16
Source File: WindowsRootPaneUI.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 17
Source File: WindowsRootPaneUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 18
Source File: WindowsRootPaneUI.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 19
Source File: WindowsRootPaneUI.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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); } } }
Example 20
Source File: WindowsRootPaneUI.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
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); } } }