简体   繁体   中英

Getting selected value from a JOptionPane input dialog

I'm trying to figure out how to get a selected value from a JOptionPane dialog box with a combo box (well, sort of).

Here is the code:

String [] locations = { "Brisbane", "Sydney", "Melbourne" };
Object city = (String) JOptionPane.showInputDialog(
    null,
    "Location?",
    "Hills School",
    JOptionPane.PLAIN_MESSAGE,
    null,
    locations,
    locations[0]);

As you can probably see I have not actually used a combo box, which is where I am having the issue. It still appears as a combo box in the JOptionPane, but I can't use getSelectedValue(). I have checked the the java website but can't seem to find an answer as to how I can get the selected value.

Is there a way to accomplish this or should I come at the JOptionPane from a different angle?

Thanks

所选值在您的city变量中,根据转换,该变量为字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM