How do I add an arrayList into a JList?

HeyWondering how you add an ArrayList's data into a JList? If anyone can show me something like:JList delList = new JList(/*insert arrayList here*/);Thanks!
[249 byte] By [Tjorriemorriea] at [2007-11-27 8:35:41]
# 1

> Wondering how you add an ArrayList's data into a

> JList?

I've not tried but the API's suggest that:

JList delList = new JList(myArrayList.toArray());

should work.

http://java.sun.com/javase/6/docs/api/javax/swing/JList.html#JList(java.lang.Object[])

http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html#toArray()

petes1234a at 2007-7-12 20:32:22 > top of Java-index,Java Essentials,New To Java...
# 2

> > Wondering how you add an ArrayList's data into a

> > JList?

>

> I've not tried but the API's suggest that:

> [code]

> JList delList = new

> JList(myArrayList.toArray());

> /code]

> should work.

>

> http://java.sun.com/javase/6/docs/api/javax/swing/JLis

> t.html#JList(java.lang.Object[])

> http://java.sun.com/javase/6/docs/api/java/util/ArrayL

> ist.html#toArray()

That will work just fine.

@OP: Keep in mind that if your ArrayList contains objects which do not have an overridden toString() method, you may not get your desired results.

Navy_Codera at 2007-7-12 20:32:22 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks! That worked just fine!BTW, I now get "malformed floating point literal" error. Any idea what that is?
Tjorriemorriea at 2007-7-12 20:32:22 > top of Java-index,Java Essentials,New To Java...
# 4

> Thanks! That worked just fine!

>

> BTW, I now get "malformed floating point literal"

> error. Any idea what that is?

Are you trying to display some type of floating point data? Is the error occuring when the JList is trying to display its contents?

If so, as Navy_Coder suggests you may need to override the "toString()" method of the object that is being displayed in the JList.

If this is not it, where in your code are you seeing this error?

petes1234a at 2007-7-12 20:32:22 > top of Java-index,Java Essentials,New To Java...