fixed focus in password dialog
This commit is contained in:
parent
b193ff649a
commit
be40fe132f
@ -1673,20 +1673,41 @@ public class FilePanelTab extends JPanel {
|
|||||||
public String requestPassword(String archiveName) {
|
public String requestPassword(String archiveName) {
|
||||||
final String[] result = new String[1];
|
final String[] result = new String[1];
|
||||||
try {
|
try {
|
||||||
if (SwingUtilities.isEventDispatchThread()) {
|
Runnable showPasswordDialog = () -> {
|
||||||
JPasswordField pf = new JPasswordField();
|
JPasswordField pf = new JPasswordField() {
|
||||||
int ok = JOptionPane.showConfirmDialog(FilePanelTab.this, pf, "Enter password for " + archiveName, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
@Override
|
||||||
if (ok == JOptionPane.OK_OPTION) {
|
public void addNotify() {
|
||||||
result[0] = new String(pf.getPassword());
|
super.addNotify();
|
||||||
}
|
requestFocusInWindow();
|
||||||
} else {
|
}
|
||||||
SwingUtilities.invokeAndWait(() -> {
|
};
|
||||||
JPasswordField pf = new JPasswordField();
|
|
||||||
int ok = JOptionPane.showConfirmDialog(FilePanelTab.this, pf, "Enter password for " + archiveName, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
Object[] message = {
|
||||||
if (ok == JOptionPane.OK_OPTION) {
|
"Enter password for " + archiveName,
|
||||||
result[0] = new String(pf.getPassword());
|
pf
|
||||||
|
};
|
||||||
|
|
||||||
|
JOptionPane pane = new JOptionPane(message, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
JDialog dialog = pane.createDialog(FilePanelTab.this, "Password Required");
|
||||||
|
|
||||||
|
dialog.addWindowFocusListener(new java.awt.event.WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowGainedFocus(java.awt.event.WindowEvent e) {
|
||||||
|
pf.requestFocusInWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dialog.setVisible(true);
|
||||||
|
Object selectedValue = pane.getValue();
|
||||||
|
if (selectedValue != null && (Integer) selectedValue == JOptionPane.OK_OPTION) {
|
||||||
|
result[0] = new String(pf.getPassword());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (SwingUtilities.isEventDispatchThread()) {
|
||||||
|
showPasswordDialog.run();
|
||||||
|
} else {
|
||||||
|
SwingUtilities.invokeAndWait(showPasswordDialog);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result[0] = null;
|
result[0] = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user