Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Default MenuBar ignores keystrokes



Hello!

I would like to use default menu bar. Here is code I am using:

public class ApplicationAdapter implements ApplicationListener {

    public static void installSupport() {
        Application app = Application.getApplication();
        app.addApplicationListener(new ApplicationAdapter());

        // create default MenuBar for all windows
        JMenuBar menuBar = new JMenuBar();

        JMenu file = new JMenu("File"); // TODO i18n
        menuBar.add(file);

        file.add(new JMenuItem(new CloseWindowAction()));

MainFrame.getInstance().setJMenuBar(menuBar); // [1] comment this for tests
app.setDefaultMenuBar(menuBar);
}
}


public class CloseWindowAction extends AbstractAction {

    public CloseWindowAction() {
        putValue(NAME, "Close"); // TODO i18n
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_W,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    }

    public void actionPerformed(ActionEvent e) {
        // TODO implement method CloseWindowAction.actionPerformed()
        System.out.println("Close window action performed.");
    }
}

And now where is problem. If I launch application with line [1] commented, application didn`t respond to Cmd-W keystroke. Once I added that line, action is called after pressing Cmd-W. But there is no visual feedback for user. I can only see in log my message. So my questions are:

1) Is it really nessecary necessary to add JMenuBar to window? Yes, I know it should be because of other OS`s. But I make this application only for Mac OS X, so I don`t care.
2) Shouldn`t be there some visual feedback like without using default menubar? If it is only bug, i will report it. But maybe I am doing something wrong. Thats the reason I ask first here.


Marian Bouček
Java programmer

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.