keyListener on a JDialog
Hi all,
I am trying to add a key listener to a JDialog. Actually, this code used to worke well with SDK earlier than 1.6.
When I run the application the JDialog shows up and the key listeners works fine as long as I do nothing. But as soon as I move the dialog, or if its content changes (there is an image in the background that changes periodically), the listener stops working.
Here is the (simpliefied) code:
publicclass Problemextends JDialog{
privatestatic JPanel panel =null;
public CamViewer(String url){
this.addKeyListener(new KeyListener(){
publicvoid keyPressed(KeyEvent e){
doSomething(e);
}
publicvoid keyTyped(KeyEvent e){
}
publicvoid keyReleased(KeyEvent e){
}
});
panel =new JPanel(){
publicvoid paintComponent(Graphics g){
g.drawImage(getIcon().getImage(), 0, 0,null);
setOpaque(false );
super.paintComponent(g);
}
};
scrollPane =new JScrollPane( panel );
setContentPane( scrollPane );
}
void doSomething(KeyEvent ke){
// do some work
}
publicstaticvoid main(String [] args){
Problem frame =new Problem();
frame.setVisible(true);
}
}
Does anyone have an idea were am I wrong? Thanks!

