Why does focusGained get recalled?
I am developing some dialogs which pop up as soon as a textfield subclass gets focus. This works fine, except that the focusGained method gets recalled, regardless of what I do - I have had to use a nasty hack to ignore the second invocation. Here is code , with the hack :
public void focusGained(FocusEvent e) {
if (eventcount++ % 2 != 0) {
KeyboardFocusManager manager =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.focusNextComponent();
return;
}
DataTypeDialog dialog = new DataTypeDialog(null, "Data Type");
dialog.setVisible(true);
DataTypeField.this.setText(dialog.getValue());
dialog.dispose();
}
Below is the code I was hoping would work, but doesn't :
public void focusGained(FocusEvent e) {
DataTypeDialog dialog = new DataTypeDialog(null, "Data Type");
dialog.setVisible(true);
DataTypeField.this.setText(dialog.getValue());
dialog.dispose();
KeyboardFocusManager manager =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.focusNextComponent();
}
Any ideas why this hack is required - or indeed if I am going about the problem in the wrong way?
I look forward to any comments.

