hi i’m using swing and in my main frame(JFrame) i want that when ever user press + key one window lets say test should appear.
my key listener works fine if i don’t call the show method of the newly added JInternalFrame but when i call the show method of my JInternalFrame the KeyListener stops listening any more.
i’ve tried a lot to solve it but all in vain so any help regarding this will be appreciated.
thanks.
this is my keyListener
_mainFrameKeyListener = new KeyListener()
{
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
System.out.println("the key pressed Id is : " + arg0.getKeyCode());
if(arg0.getKeyCode() == 107){
test Test = new test();
_mainDesktopPane.add(Test);
Test.show();
}
}
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
};
Sounds like you want a hot key instead of a key listener to avoid focus issues.
http://helpdesk.objects.com.au/java/how-to-specify-a-hot-key-for-a-swing-application