0

I am developing a client application that accepts or rejects certificates from a server just as any browser would do. More detailed explanation of my work can be found in this Code Review.

The method I am using to display my certificates is,

public boolean DisplayCertficate(java.security.cert.X509Certificate cert){
final JPanel panel = new JPanel();
String message =  " Do you want to accept this certificate? \n"
        + "\n Certificate for: " + cert.getSubjectDN()
        + "\n Certificate issued by: "
        + cert.getIssuerDN()
        + "\n The certificate is valid from: "
        + cert.getNotBefore() + "\n Certificate SN#: "
        + cert.getSerialNumber() + "\n Generated with: "
        + cert.getSigAlgName();

String title = "Security Alert";
String[] options = { "yes", "no" };
int confirm = JOptionPane.showOptionDialog(panel, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
        null, options, options[0]);

if (confirm == JOptionPane.YES_OPTION){
    return true;
} else if (confirm == JOptionPane.NO_OPTION) {
    return false;
}
else{
    return false;
}
}

And this function is called in another class:

if(PopUp.DisplayCertficate((X509Certificate) c) == true){
    return true;
}
else{
    PopUp.NeedCertificate();
    return false;
}

This works fine if I need a certificate from a single server. If I am trying to load multiple servers one after another into my Client UI, multiple JOptionPane windows open up in a quick succession. This freezes the displayed certificate window.

Is there a way I can open a new JOptionPane window in a different location for each certificate I try to load?

Community
  • 1
  • 1
agenthost
  • 748
  • 2
  • 9
  • 24

1 Answers1

0

Look here for more information on how to set the location of a JOptionPane.

You’d have to create a JDialog from the JOptionPane object and set the location of the dialog.

To make the window open in a different location, you could save the last x and y coordinates, and open it at (x + 5, y + 5), or somewhere relative to the last opened JOptionPane.

Community
  • 1
  • 1