Question

Can i do that ? I want to set default value of my option pane is 9090.. This is my option pane code

private static int setPortNumber()
{
    String portNumber = JOptionPane.showInputDialog(frame,
            "Enter the Port number for server creation","Server Connection\n",
            JOptionPane.OK_CANCEL_OPTION);
    int PORT = Integer.parseInt(portNumber);

    return PORT;

}   
Was it helpful?

Solution

Yes you can do that.

private static int setPortNumber()
{

    String [] possiblePorts = { "9090", "8080", "8081" }; 
    String selectedPort = (String) JOptionPane.showInputDialog(frame, "Select the Port number for server creation", "Server Connection\n", JOptionPane.OK_CANCEL_OPTION, null, possiblePorts, possiblePorts[0]);

    int PORT = Integer.parseInt(selectedPort);

    return PORT;

}

In this way user need not to write just select.

OTHER TIPS

String portNumber = (String) JOptionPane.showInputDialog(frame,
        "Enter the Port number for server creation",
        "Server Connection\n", JOptionPane.OK_CANCEL_OPTION, null,
        null, "9090");

Read the docs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top