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);
}
}
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);
}
}