title: JOptionPane - check user input and prevent from closing until conditions are met
body: <p>Please can someone tell me if there is a convenient way of prevent <code>JOptionPane</code> from closing upon clicking OK unless the conditions for user input fields are met?</p>
  
  <p>Or do I have no choice but to use <code>JFrame</code>?</p>
  
  <p>My validation logic so far. Doesn't seem to work because the buttons are one-time clickable to some reason...</p>
  
  <pre><code>final JDialog dialog3 = new JDialog(OmniGUI.getFrame(), "Create new Node - id:" + newNodeID);
  dialog3.setContentPane(theOPane);
  dialog3.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
  
  theOPane.addPropertyChangeListener(new PropertyChangeListener(){
     public void propertyChange(PropertyChangeEvent e) {
  
         if(e.getSource() == theOPane){
             String val = (String) ((JOptionPane) e.getSource()).getValue();
  
             if(val=="Create"){
                 System.out.println("Checking content");                      
  
                 if(!valid){
                     System.out.println("closing the window");    
  
                     dialog3.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                     dialog3.removeAll();
                     dialog3.dispatchEvent(new WindowEvent(dialog3, WindowEvent.WINDOW_CLOSING));
                 }
  
             }
         }
     }    
  });
  
      dialog3.setLocation(p);
      dialog3.pack();
      dialog3.setVisible(true);
  </code></pre>