0

如果我使用的是 JOptionPane 消息对话框,我将如何在消息部分中显示整个数组,例如这个小片段?还是有可能?

 public void showTheMessage()

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

3 回答 3

0

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

于 2009-11-29T06:27:35.383 回答
0

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

String colors = "";
for(int i = 0; i < arrayOfColors.length; i++)
    colors += arrayOfColors[i] + " ";
于 2009-11-29T06:27:37.533 回答
0

如果它是一组 Color 对象

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

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

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

请注意,使用 StringBuilder 更快,但这只是我猜的一个小数组。

于 2009-11-29T10:20:29.550 回答