title: swing focus issue, lost focus, focusgain not invoked
body: <p>I have a complex and heavy swing client application which contains many modal compponents, jdialogs, internal frames etc. on some cases, a problem occurs and it is impossible to focus on swing textfields anymore. You may click on some jbuttons, jcheckboxes but it is impossible to focus and edit values on editable jtextfields anymore. The <em>gainfocus</em> events of editable textfields are not triggered anymore, only the <em>requestfocus</em> methods are invoked when you perform click on textfields.
  I found a way(hack) so resolve the problematic case, when the trouble case occurs, and you show some <em>joptionpane</em> message or <em>modal jdialog</em> and close it by clicking or disposing, the problem goes away any you may click onto the textfields and edit them.
  As a solution, i do some check, if you try focusing on a component, i start a timer thread in the requestfocus event of clicked textfield and keep the instance as <strong>focusrequesting</strong> component. After some time i check the last focused component by </p>
  
  <p><em>KeyboardManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner()</em></p>
  
  <p>If no problem occured, and the textfield gained the focus, the returned object (retur value of getPermanentFocusOwner) is the same instance as the <strong>focusrequesting</strong> component. But if the problematic case occured, the returned object is different from the focus requesting one and i open my temporarily jdialog by:</p>
  
  <pre><code>JDialog dialog=new OptionPane().createDialog(KeyboardFocusManager.getCurrentFocusManager().getActiveWindow(), "");
  dialog.setModal(true); 
  // MUST be modal to fix the lost focus case
  // start closing thread, which closes the dialog after some few time by dialog.dispose
  new Closer(dialog).start();
  dialog.setVisible(true);
  </code></pre>
  
  <p>This mechanism works, i now it is not very stable. And on some cases,the <em>dialog.dispose()</em> does not work, the temporarily windows remains always on the screen, not closeable, and because it is modal, client can not do any actions anymore. The dialog MUST be modal to solve the focus problem, because non-modal dialogs does not resolve the focus problem declared above. The dispose method of jdialog has many synchronized blocks, mutex objects etc, I think there occurs some deadlocks.</p>
  
  <p>Any better mechanism suggestions, ideas? I know the best solution is to check the current application, analyse it or rewrite it. But it is very complex, heavy and model and view is not well properly organised. I have short time because the client is waiting, need some temporarily solutions, tricks or hacks.</p>