How to set global key for particular function?

J

James

Anyone know how to set global key for a particular function?

last time in JRE1.3, I had write a code under JFrame's fromKeyPressed. With
that, when user press shift+space bar or ctrl+space bar ,it can switch the
tabindex from 1 to another. (shortkey for switching the tabindex) it can
handle very well in JRE1.3 but now in JRE 1.4 because of the focus subsystem
had been change, it can't preform this code, now is not become global key
under JFrame's fromKeyPressed. I don't know how to set that
KeyboardFocusManager or change the focus traversal policy. Can anyone show
me how to set the ctrl+space and shift+space as global key for particular
function. Change keymap?
how to change?
all affect?


private void formKeyPressed(java.awt.event.KeyEvent evt) {
// Add your handling code here:
KeyStroke
ky=KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SPACE,java.awt.Event.CT
RL_MASK);

if((ky.getKeyCode()==evt.getKeyCode())&&(evt.isControlDown())&&(tabpnPage.ge
tSelectedIndex()<tabpnPage.getTabCount()-1))
{
tabpnPage.setSelectedIndex(tabpnPage.getSelectedIndex()+1);
}
else
if((ky.getKeyCode()==evt.getKeyCode())&&(evt.isShiftDown())&&(tabpnPage.getS
electedIndex()>0))
{
tabpnPage.setSelectedIndex(tabpnPage.getSelectedIndex()-1);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top