使用JOptionPane

时间:2009-11-29 06:16:52

标签: java joptionpane

如果我使用的是JOptionPane消息对话框,我怎样才能在消息部分显示整个数组,例如这个小片段?或者甚至可能吗?

 public void showTheMessage()

{
 JOptionPane.showMessageDialog(null,"These are are all the colors to
          choosfrom,\n"+ arrayOfcolors[the whole array], "Color box");
 }

3 个答案:

答案 0 :(得分:0)

showOptionDialog方法允许用户从一组选项中选择一个元素,我认为这是您正在寻找的。

答案 1 :(得分:0)

最简单的方法是将数组的所有元素连接成一个大字符串。

String colors = "";
for(int i = 0; i < arrayOfColors.length; i++)
    colors += arrayOfColors[i] + " ";

答案 2 :(得分:0)

如果是一个Color对象数组

   String colors="";
   for (Color c: arrayOfColors) 
       colors+= c.toString() + " ";

否则,如果是一个String对象数组

   String colors="";
   for (String s: arrayOfColors) 
       colors+= s + " ";

请注意,使用StringBuilder要快得多,但我猜这只是一个小阵列。