java – joptionpane默认值showinputdialog

我能这样做吗?我想设置我的选项窗格的默认值是9090 ..
这是我的选项窗格代码

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;

}   

解决方法:

是的,你可以这样做.

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;

}

这样用户不需要只写选择.

上一篇:java – JScrollPane中的JTextArea包装单词但缺少字母


下一篇:练手THINKPHP5过程和bootstrap3.3.7