如果我使用的是 JOptionPane 消息对话框,我将如何在消息部分中显示整个数组,例如这个小片段?还是有可能?
public void showTheMessage()
{
JOptionPane.showMessageDialog(null,"These are are all the colors to
choosfrom,\n"+ arrayOfcolors[the whole array], "Color box");
}
如果我使用的是 JOptionPane 消息对话框,我将如何在消息部分中显示整个数组,例如这个小片段?还是有可能?
public void showTheMessage()
{
JOptionPane.showMessageDialog(null,"These are are all the colors to
choosfrom,\n"+ arrayOfcolors[the whole array], "Color box");
}
showOptionDialog方法允许用户从选项数组中选择一个元素,我认为这就是您要寻找的。
最简单的做法是将数组的所有元素连接成一个大字符串。
String colors = "";
for(int i = 0; i < arrayOfColors.length; i++)
colors += arrayOfColors[i] + " ";
如果它是一组 Color 对象
String colors="";
for (Color c: arrayOfColors)
colors+= c.toString() + " ";
否则,如果它是一个 String 对象数组
String colors="";
for (String s: arrayOfColors)
colors+= s + " ";
请注意,使用 StringBuilder 更快,但这只是我猜的一个小数组。