【问题标题】:drop down dialog boxes下拉对话框
【发布时间】:2013-03-20 11:39:06
【问题描述】:

我从 oracle 网站获得了这个下拉框示例:

Object[] possibilities = {"ham", "spam", "yam"};
String s = (String)JOptionPane.showInputDialog(
                frame,
                "Complete the sentence:\n"
                + "\"Green eggs and...\"",
                "Customized Dialog",
                JOptionPane.PLAIN_MESSAGE,
                icon,
                possibilities,
                "ham");

//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
setLabel("Green eggs and... " + s + "!");
return;
}

//If you're here, the return value was null/empty.
setLabel("Come on, finish the sentence!");

我只是想知道你如何改变每个选择的作用?例如,我是否需要更改语句if ((s != null) && (s.length() > 0)) { 中的某些内容,以便我可以编辑第一个字符串项?

【问题讨论】:

  • “每个选择会做什么”是什么意思?

标签: java swing dialog


【解决方案1】:

检查用户选择了哪个项目并做某事非常简单

if ((s != null) && (s.length() > 0)) {

     if(s.equals(possibilities[0]);
         //HAM is chosen do something
     else if(s.equals(possibilities[1]);
         //spam and so on..........
     return;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    相关资源
    最近更新 更多