I\'m having trouble with the default Java KeyListener in my project. I noticed that the KeyListener doesn\'t seem to get KeyEvents forwarded sometimes when I start.
Don't know if this is related to your problems, but due to the intermittent nature of it perhaps it is...You should execute setVisible() last and in the swing thread. You could call setSize after setVisible if you want to, but the user might see a flicker and it likewise should be done in the swing thread. Do this as your last step:
SwingUtilities.invokeLater( new Runnable() {
public void run() {
window.setVisible( true );
}
} );
To do this, you will also need to make window declaration final:
...
final JFrame window = new JFrame();
...