Java Code Examples for javax.swing.JFrame.getJMenuBar()

The following are Jave code examples for showing how to use getJMenuBar() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: ShortcutAndMenuKeyEventProcessor.java   Source Code and License Vote up 7 votes
public boolean postProcessKeyEvent(KeyEvent ev) {
    if (ev.isConsumed())
        return false;

    if (processShortcut(ev))
        return true;

    Window w = SwingUtilities.windowForComponent(ev.getComponent());        
    if (w instanceof Dialog && !WindowManagerImpl.isSeparateWindow(w))
        return false;
    
    JFrame mw = (JFrame)WindowManagerImpl.getInstance().getMainWindow();
    if (w == mw) {
        return false;
    }

    JMenuBar mb = mw.getJMenuBar();
    if (mb == null)
        return false;
    boolean pressed = (ev.getID() == KeyEvent.KEY_PRESSED);        
    boolean res = invokeProcessKeyBindingsForAllComponents(ev, mw, pressed);
    
    if (res)
        ev.consume();
    return res;
}
 
Example 2
Project: openjdk-jdk10   File: SilenceOfDeprecatedMenuBar.java   Source Code and License Vote up 6 votes
@Override
public void run() {
    final JFrame frame = new DeprecatedFrame();
    try {
        final JMenuBar bar = new JMenuBar();
        frame.setJMenuBar(bar);
        frame.setBounds(100, 100, 100, 100);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        if (bar != frame.getJMenuBar()) {
            throw new RuntimeException("Wrong JMenuBar");
        }
    } finally {
        frame.dispose();
    }
}