Search code examples
javaswingjoptionpane

Open a JOptionPane by another JOptionPane


I am using a JOptionPane to get a string. By klicking "OK" the string is saved. Now i want the second JOptionPane to pop-up to enter the second necassary string. Is there any opportunity to add an ActionListener to the "Ok"-button from the first JOptionPane? Or what is the best solution of my problem? I also checked the docs, but did not found something useful yet.

My JOptionPanes lool nearly similar.


Solution

  • The simple way for me is just combining it with Confirmation Dialog !

    import javax.swing.JOptionPane;
    
    public class ConfirmDialog
     {
        public static void main (String args []){
    
    
        int choose= JOptionPane.showConfirmDialog(null, "Open Dialog  ??");
    
        if(choose== JOptionPane.YES_OPTION) {
            JOptionPane.showMessageDialog(null,"You Clicked Yes !!");
        } else if(choose== JOptionPane.NO_OPTION) {
                    JOptionPane.showMessageDialog(null,"You Clicked NO");
        }
            }
             }