sokolovic 0 Newbie Poster

I've already posted similar question at JavaRanch but didn't get the solution.
Here is the issue:
I need to detect CAPS LOCK state after minimizing and restoring frame.

This is what I did:
Run application
CAPS LOCK is off
Minimize, restore and get message "Caps lock off"
Then I minimize it again, turn CAPS LOCK on, but when restore it I get the same message again, saying that "Caps lock off", even though CAPS is on now.

Correct message is displayed only if I change CAPS LOCK state when frame is in focus. Otherwise not.

Here is a testing code giving the same results:

public class FrameTest extends JFrame
    implements WindowListener
{
    public FrameTest()
    {
        super();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        addWindowListener(this);
        setSize(300, 300);
    }

    public void windowOpened(WindowEvent e) { }

    public void windowClosing(WindowEvent e) { }

    public void windowClosed(WindowEvent e) { }

    public void windowIconified(WindowEvent e) { }

    public void windowDeiconified(WindowEvent e)
    {
        if(Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK))
        {
            JOptionPane.showMessageDialog(null, "Caps lock on");
        }
        else
        {
            JOptionPane.showMessageDialog(null, "Caps lock off");
        }
    }

    public void windowActivated(WindowEvent e) { }

    public void windowDeactivated(WindowEvent e) { }

    // Run application
    public static void main(String[] args)
    {
        (new FrameTest()).setVisible(true);
    }
}

Can anyone here help with this?
Cheers!
sokolovic