Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problems with JMenuItem Posted by yanghui1023 on 15 Oct 2006 at 4:54 AM
This message was edited by yanghui1023 at 2006-10-15 5:51:3

I want my menuitem to show as"New(N) " and there is an underline under the second letter N.my code is:


jMenuItemNew.setMnemonic(java.awt.event.KeyEvent.VK_N);



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!
Report
Re: problems with JMenuItem Posted by zibadian on 15 Oct 2006 at 5:12 AM
: 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:
:
:
: 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);
:

:
: 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:
  jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),  
  java.awt.event.InputEvent.CTRL_MASK));

Also check the constants you're using.
Report
Re: problems with JMenuItem Posted by yanghui1023 on 15 Oct 2006 at 5:59 AM
: : 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:
: :
: :
: : 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);
: :

: :
: : 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:
:
:   jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),  
:   java.awt.event.InputEvent.CTRL_MASK));
: 

: 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
Report
Re: problems with JMenuItem Posted by zibadian on 15 Oct 2006 at 6:07 AM
: : : 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:
: : :
: : :
: : : 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);
: : :

: : :
: : : 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:
: :
: :   jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),  
: :   java.awt.event.InputEvent.CTRL_MASK));
: : 

: : 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.
Report
Re: problems with JMenuItem Posted by yanghui1023 on 15 Oct 2006 at 6:17 AM
: : : : 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:
: : : :
: : : :
: : : : 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);
: : : :

: : : :
: : : : 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:
: : :
: : :   jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),  
: : :   java.awt.event.InputEvent.CTRL_MASK));
: : : 

: : : 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 .
Report
Re: problems with JMenuItem Posted by zibadian on 15 Oct 2006 at 7:21 AM
: : : : : 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:
: : : : :
: : : : :
: : : : : 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);
: : : : :

: : : : :
: : : : : 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:
: : : :
: : : :   jMenuItemNew.setAccelerator(KeyStroke.getKeyStroke(Character.valueOf("n"),  
: : : :   java.awt.event.InputEvent.CTRL_MASK));
: : : : 

: : : : 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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.