From d030d4ca3e16834d028874b11c42b02b38a7a940 Mon Sep 17 00:00:00 2001 From: Kai Kramer Date: Thu, 26 Mar 2015 16:29:37 +0100 Subject: [PATCH] fixed focus problem with new password dialog --- .../gui/password/DGetNewPassword.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/kse/src/net/sf/keystore_explorer/gui/password/DGetNewPassword.java b/kse/src/net/sf/keystore_explorer/gui/password/DGetNewPassword.java index 0aaf35088..8ae97f792 100644 --- a/kse/src/net/sf/keystore_explorer/gui/password/DGetNewPassword.java +++ b/kse/src/net/sf/keystore_explorer/gui/password/DGetNewPassword.java @@ -41,10 +41,11 @@ import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; import net.sf.keystore_explorer.crypto.Password; import net.sf.keystore_explorer.gui.JEscDialog; @@ -229,12 +230,21 @@ public void windowClosing(WindowEvent evt) { setResizable(false); getRootPane().setDefaultButton(jbOK); - + pack(); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - jpfFirst.requestFocus(); + // fix for focus issues: request focus after dialog was made visible + jpfFirst.addAncestorListener(new AncestorListener() { + @Override + public void ancestorRemoved(AncestorEvent event) { + } + @Override + public void ancestorMoved(AncestorEvent event) { + } + @Override + public void ancestorAdded(AncestorEvent event) { + JComponent component = event.getComponent(); + component.requestFocusInWindow(); } }); }