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:
Right now if i click on any of the buttons, the dialog get closed, how should i change that?
My Code so far(most of it):
public MakeBookingForm()
{
components = new ArrayList<>();
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;
}