Article View: borland.public.jbuilder.java.swing
Article #11304Re: Keyboard-shortcuts to JButtons
From: Felix Lipov
Date: Thu, 17 Jun 1999 00:00
Date: Thu, 17 Jun 1999 00:00
39 lines
1830 bytes
1830 bytes
Could you please post an example. In my case I am extending from
JToolBar and am implementing ActionListener. Here is the code I was
using:
pbNew=new JButton("new");
pbNew.setActionCommand("new");
pbNew.addActionListener(this);
pbNew.registerKeyboardAction(this, "new",
KeyStroke.getKeyStroke('n', java.awt.Event.CTRL_MASK),
WHEN_IN_FOCUSED_WINDOW);
and then in the implementatin of actionPerformed:
if (e.getActionCommand().equals("new")) {
System.out.println("new button");
pbNew_OnClick();
}
Now if I were to do simply KeyStroke.getKeyStroke('n') w/o the CTRL
MASK, it works fine just by my typing the 'n' key. But I cannot get it
to work as CTRL-n or any other modifier key combination for some reason.
Thank you.
Khurram Shakir wrote:
>
> Felix
> see java documentation about
> javax.swing.KeyStroke class,
> hope this class documentation will help you to providing your desired
> functionality. if you will still not able to do so then reply me back so I
> will give you specific source code oriented answer.
> hope this will help...
>
> --
> Khurram Shakir
> Java Developer
> Progressive Systems(Pvt.) Limited
> kshakir@prosys.com.pk
> ICQ # : 17135971
Technical Details
Message-ID:
<37690730.B67197AF@thortech.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<376141F0.154F3520@thortech.com> <7jrkl9$b5516@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d88e234f13e2c021 X-Google-Attributes: gid111d45,public From: Felix Lipov <felix.lipov@thortech.com> Subject: Re: Keyboard-shortcuts to JButtons Date: 1999/06/17 Message-ID: <37690730.B67197AF@thortech.com> X-Deja-AN: 490683141 Content-Transfer-Encoding: 7bit References: <376141F0.154F3520@thortech.com> <7jrkl9$b5516@forums.borland.com> To: Khurram Shakir <kshakir@prosys.com.pk> Content-Type: text/plain; charset=us-ascii Organization: Thor Technologies Inc. Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing