KeyboardFocusManager not work well in WindowsXP/2000

I have a JButton in a frame. If clicking the button a dialog will show up. I set CurrentKeyboardFocusManager in the dialog's constructor. The part of code is:

JButton button = new JButton();

button.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

CreateDialog dlg = new CreateDialog(frame, model);

}

});

public CreateDialog(Frame parent, MediaPresentationModel model)

{

super(parent, "Item Editor", true);

this.model = model;

this.mode = mode;

this.parent = parent;

// register a focus manager that transfers focus on 'Enter'

KeyboardFocusManager.setCurrentKeyboardFocusManager(

new DefaultKeyboardFocusManager()

{

public boolean postProcessKeyEvent(KeyEvent e)

{

Component c = e.getComponent();

// the instanceof JTable check is because we want Enter to take the

// user to the next cell not the next component...

if (e.getKeyCode() == KeyEvent.VK_ENTER &&

e.getID() == KeyEvent.KEY_PRESSED &&

!(c instanceof JTable))

{ focusNextComponent(); }

return true;

}

});

}

. . . . . .

}

There's no any problem when I run it in Linux. But in Windows only when the first time to click the button, ENTER key works fine(when clicking ENTER key,the focus went to next component); when I closed the dialog and click button to open it again, clicking ENTER key didn't do anything; the focus didn't move. I found that the first time to initiate the dialog I got the returned FocusTraversalPolicy is "LayoutFocusTraversalPolicy" but when I clicked button again the returned policy is "defaultFocusTraversalPolicy" and the returned next component is null. I initiated the dialog the same way each time why it works in Linux but not in Windows?

[1903 byte] By [lmSuna] at [2007-11-27 10:18:11]
# 1

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

camickra at 2007-7-28 15:56:01 > top of Java-index,Desktop,Core GUI APIs...