Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Azrel

macrumors regular
Original poster
Jun 8, 2005
117
0
Hey guys,

I think this is a Mac issue, but for some reason my MenuShortCut's don't seem to work:

JMenuItem newItem = new JMenuItem("New Game \t ?N", KeyEvent.VK_A);
newItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
newGame();
}
});
fileMenu.add(newItem);

Also what is the KeyCode for the Apple key? And how do I use the "four leaf clover" instead of the Apple sign? I.E, it'll have "New Game.." and then the four leaf clover with an N next to it in the menu. Thanks!!
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
I don't have my Mac in front of me, or a Java compiler, but from looking at the JavaDoc, I think you should try:

Code:
int keyCode = java.awt.event.KeyEvent.VK_N;  // Your code used VK_A
int modifiers = java.awt.event.InputEvent.META_DOWN_MASK;
javax.swing.KeyStroke ks = javax.swing.KeyStroke.getKeyStroke(
    keyCode, modifiers);
JMenuItem newItem = new JMenuItem( "New Game" );
newItem.setAccelerator( ks );
 

Azrel

macrumors regular
Original poster
Jun 8, 2005
117
0
I solved it by just using Menu rather than JMenu. Thanks anyway :)
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
Azrel said:
I solved it by just using Menu rather than JMenu. Thanks anyway :)

But are you using a JFrame or a Frame? It's best not to mix Swing and AWT components, but rather to keep things consistent, otherwise you'll see repaint issues.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.