problems with JMenuItem - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

problems with JMenuItem

yanghui1023yanghui1023 Posts: 24Member
[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

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • yanghui1023yanghui1023 Posts: 24Member
    : : 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
  • zibadianzibadian Posts: 6,349Member
    : : : 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.
  • yanghui1023yanghui1023 Posts: 24Member
    : : : : 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 .
  • zibadianzibadian Posts: 6,349Member
    : : : : : 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.