[英]Using JOptionPane
如果我使用的是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的速度要快得多,但是我猜这只是一个很小的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.