views:

209

answers:

3

if i was using a JOptionPane message dialog box how would I be able to show an the whole array in the message section such as this little snipit? or would that evenbe possible?

 public void showTheMessage()

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

The showOptionDialog method lets the user select a single element from an array of options, which I think is what you're looking for.

Kevin Montrose
A: 

The easiest thing to do would be to concatenate all the elements of the array into one big string.

String colors = "";
for(int i = 0; i < arrayOfColors.length; i++)
    colors += arrayOfColors[i] + " ";
jonescb
exactly what i was looking for but some strange reason i could not think of how to do this array or loop and I had one similar. God Bless thanks alot
daddycardona
What does showing all the colors do, if the user can't select one? There is a better solution to the problem.
camickr
@camicker-I am working on a school project using javax.swing package and I just need to display all the colors i have in that array on the JOptionPane's show messageDialog box. This worked just for the display part.
daddycardona
A: 

In case its an array of Color objects

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

Otherwise if its an array of String objects

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

Just a note, using StringBuilder is much faster, but this is just a small array i guess.

medopal