title: Creating a JOptionPane with custom actions on buttons
body: <p>I'm trying to create a custom dialog with input from the user, after each step(of the input) the information is verified, and if it's correct a new panel appears, and the user can continue adding info. To do this i'm using JOptionPane. I'll have three buttons "Ok", enabled only if the user went trough the whole input proces, "Next", to check if the inputted info is correct and show a new pane, and lastly "Cancel", to cacel. Here how it looks:</p>
  
  <p><a href="https://i.stack.imgur.com/EzuMv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EzuMv.png" alt="enter image description here"></a></p>
  
  <p>Right now if i click on any of the buttons, the dialog get closed, how should i change that?</p>
  
  <p>My Code so far(most of it): </p>
  
  <pre><code>public MakeBookingForm()
  {
      components = new ArrayList&lt;&gt;();
  
      this.title = "Make Booking";
      setMessageType(JOptionPane.PLAIN_MESSAGE);
      setRootPane(null);
      setOptions(new String[] { "OK", "Next", "Cancel" });
      setOptionSelection(0);
  
      JPanel roomNumPanel = new JPanel();
      lblRoomNum = new JLabel( "Enter the booking number" );
      roomNumPanel.add(lblRoomNum);
      txtFldRoomNum = new JTextField(20);
      roomNumPanel.add(txtFldRoomNum);
      this.addComponent(roomNumPanel);
  
  }
  
  public void show() //the function i use to show the form
  {
      int optionType = JOptionPane.OK_CANCEL_OPTION;
      //JOptionPane.OK_OPTION
      Object optionSelection = null;
  
      if(options.length != 0)
      {
          optionSelection = options[optionIndex];
      }
  
      int selection = JOptionPane.showOptionDialog(rootPane,
              components.toArray(), title, optionType, messageType, null,
              options, optionSelection);
  
      System.out.println(selection);
  
      //return selection;
  }
  </code></pre>