problems with JMenuItem

[b][red]This message was edited by yanghui1023 at 2006-10-15 5:51:3[/red][/b][hr]
I want my menuitem to show as"New(N) " and there is an underline under the second letter N.my code is:

[blue]
jMenuItemNew.setMnemonic(java.awt.event.KeyEvent.VK_N);
[/blue]


when i press the combination key Alt and N,it has the same effect wih I click the menuitem.But how can i let it show as "New(N) " with a line under the second letter N.
thanks!

Comments

  • : hello,
    : want my menuitem to show the text "New(N) Ctrl+N",and when i press the combination key ctrl and N the system will create an Event,which has the same effect with I click the menuitem.
    : My code is:
    :
    : [grey]
    : javax.swing.KeyStroke stroke;
    : int event=java.awt.event.KeyEvent.VK_N;
    : int inputEvent=java.awt.event.InputEvent.CTRL_DOWN_MASK;
    : stroke=javax.swing.KeyStroke.getKeyStroke(event, inputEvent);
    : jMenuItemNew.setAccelerator(stroke);
    : [/grey]
    :
    : but when i press the combination key Ctrl and N,there is no response.
    : Did i do wrong?
    : Any suggestions would be welcom!
    : thanks in advance!
    :
    Why so elaborate? The KeyStoke class defines a static method called getKeystroke(), which creates the necessary key stroke object:
    [code]
    jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),
    java.awt.event.InputEvent.CTRL_MASK));
    [/code]
    Also check the constants you're using.
  • : : hello,
    : : want my menuitem to show the text "New(N) Ctrl+N",and when i press the combination key ctrl and N the system will create an Event,which has the same effect with I click the menuitem.
    : : My code is:
    : :
    : : [grey]
    : : javax.swing.KeyStroke stroke;
    : : int event=java.awt.event.KeyEvent.VK_N;
    : : int inputEvent=java.awt.event.InputEvent.CTRL_DOWN_MASK;
    : : stroke=javax.swing.KeyStroke.getKeyStroke(event, inputEvent);
    : : jMenuItemNew.setAccelerator(stroke);
    : : [/grey]
    : :
    : : but when i press the combination key Ctrl and N,there is no response.
    : : Did i do wrong?
    : : Any suggestions would be welcom!
    : : thanks in advance!
    : :
    : Why so elaborate? The KeyStoke class defines a static method called getKeystroke(), which creates the necessary key stroke object:
    : [code]
    : jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),
    : java.awt.event.InputEvent.CTRL_MASK));
    : [/code]
    : Also check the constants you're using.
    :

    can you help me with the method setMnemonic?
    my code is:
    jMenuItemNew.setMnemonic(java.awt.event.KeyEvent.VK_N);
    and i want there is a line under the letter N,how can i realize it?
    thanks
  • : : : hello,
    : : : want my menuitem to show the text "New(N) Ctrl+N",and when i press the combination key ctrl and N the system will create an Event,which has the same effect with I click the menuitem.
    : : : My code is:
    : : :
    : : : [grey]
    : : : javax.swing.KeyStroke stroke;
    : : : int event=java.awt.event.KeyEvent.VK_N;
    : : : int inputEvent=java.awt.event.InputEvent.CTRL_DOWN_MASK;
    : : : stroke=javax.swing.KeyStroke.getKeyStroke(event, inputEvent);
    : : : jMenuItemNew.setAccelerator(stroke);
    : : : [/grey]
    : : :
    : : : but when i press the combination key Ctrl and N,there is no response.
    : : : Did i do wrong?
    : : : Any suggestions would be welcom!
    : : : thanks in advance!
    : : :
    : : Why so elaborate? The KeyStoke class defines a static method called getKeystroke(), which creates the necessary key stroke object:
    : : [code]
    : : jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),
    : : java.awt.event.InputEvent.CTRL_MASK));
    : : [/code]
    : : Also check the constants you're using.
    : :
    :
    : can you help me with the method setMnemonic?
    : my code is:
    : jMenuItemNew.setMnemonic(java.awt.event.KeyEvent.VK_N);
    : and i want there is a line under the letter N,how can i realize it?
    : thanks
    :
    When you set the Mnemonic the line will appear automatically. It did in my program. You don't need to perform any other programming.
  • : : : : hello,
    : : : : want my menuitem to show the text "New(N) Ctrl+N",and when i press the combination key ctrl and N the system will create an Event,which has the same effect with I click the menuitem.
    : : : : My code is:
    : : : :
    : : : : [grey]
    : : : : javax.swing.KeyStroke stroke;
    : : : : int event=java.awt.event.KeyEvent.VK_N;
    : : : : int inputEvent=java.awt.event.InputEvent.CTRL_DOWN_MASK;
    : : : : stroke=javax.swing.KeyStroke.getKeyStroke(event, inputEvent);
    : : : : jMenuItemNew.setAccelerator(stroke);
    : : : : [/grey]
    : : : :
    : : : : but when i press the combination key Ctrl and N,there is no response.
    : : : : Did i do wrong?
    : : : : Any suggestions would be welcom!
    : : : : thanks in advance!
    : : : :
    : : : Why so elaborate? The KeyStoke class defines a static method called getKeystroke(), which creates the necessary key stroke object:
    : : : [code]
    : : : jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),
    : : : java.awt.event.InputEvent.CTRL_MASK));
    : : : [/code]
    : : : Also check the constants you're using.
    : : :
    : :
    : : can you help me with the method setMnemonic?
    : : my code is:
    : : jMenuItemNew.setMnemonic(java.awt.event.KeyEvent.VK_N);
    : : and i want there is a line under the letter N,how can i realize it?
    : : thanks
    : :
    : When you set the Mnemonic the line will appear automatically. It did in my program. You don't need to perform any other programming.
    :


    the line didn't appear in my program,though when i press the combination key Alt and N, it has the same effect with i click the menuitem .
  • : : : : : hello,
    : : : : : want my menuitem to show the text "New(N) Ctrl+N",and when i press the combination key ctrl and N the system will create an Event,which has the same effect with I click the menuitem.
    : : : : : My code is:
    : : : : :
    : : : : : [grey]
    : : : : : javax.swing.KeyStroke stroke;
    : : : : : int event=java.awt.event.KeyEvent.VK_N;
    : : : : : int inputEvent=java.awt.event.InputEvent.CTRL_DOWN_MASK;
    : : : : : stroke=javax.swing.KeyStroke.getKeyStroke(event, inputEvent);
    : : : : : jMenuItemNew.setAccelerator(stroke);
    : : : : : [/grey]
    : : : : :
    : : : : : but when i press the combination key Ctrl and N,there is no response.
    : : : : : Did i do wrong?
    : : : : : Any suggestions would be welcom!
    : : : : : thanks in advance!
    : : : : :
    : : : : Why so elaborate? The KeyStoke class defines a static method called getKeystroke(), which creates the necessary key stroke object:
    : : : : [code]
    : : : : jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),
    : : : : java.awt.event.InputEvent.CTRL_MASK));
    : : : : [/code]
    : : : : Also check the constants you're using.
    : : : :
    : : :
    : : : can you help me with the method setMnemonic?
    : : : my code is:
    : : : jMenuItemNew.setMnemonic(java.awt.event.KeyEvent.VK_N);
    : : : and i want there is a line under the letter N,how can i realize it?
    : : : thanks
    : : :
    : : When you set the Mnemonic the line will appear automatically. It did in my program. You don't need to perform any other programming.
    : :
    :
    :
    : the line didn't appear in my program,though when i press the combination key Alt and N, it has the same effect with i click the menuitem .
    :
    It might be that the line is not visible due to the setting "Hide indicator until alt is presses" in windows. I have that setting turned off.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories