Key Listener doesn't detect spacebar
<p>I have JTextPane and added key listener to it. Code looks like:</p>

<pre><code>class MainPanel extends JPanel {
    JTextPane codePane = new JTextPane(); 

    MainPanel() {
        add(new JScrollPane(codePane));
        codePane.addKeyListener(new KeyHandler());
    }

    private class KeyHandler extends KeyAdapter {
        @Override
        public void keyTyped(KeyEvent ev) {
            if (ev.getKeyCode() == KeyEvent.VK_SPACE) {
                System.out.println("space");
            } else {
                System.out.println("char");
            }
        }
    }
}
</code></pre>

<p>When I type "sp " i get 3 times: char. It doesn't even detect pressing SPACEBAR. How to solve it?</p>
