java - Putting an ArrayList into a JList using ArrayList#toArray method -


i'm having trouble using toarray method of arraylist class. need put content of arraylist, vecpersonnages, jlist, listeobjets, , i'd using arraylist#toarray method. managed make work putting values of list in tab , putting tab in jlist.

i did check on google found turned out not work. have tostring method in classes, however, not have tostring method in class in utilize jlist.

this how declared classes:

private jlist<personnage> listeobjets = null; private arraylist<personnage> vecpersonnages = null; 

below code try add content of arraylist jlist along things tried, noted in comments:

personnage[] tabperso = new personnage[vecpersonnages.size()]; (int = 0; < vecpersonnages.size(); i++) {     tabperso[i] = vecpersonnages.get(i); } listeobjets.setlistdata(tabperso); //listeobjets.setlistdata(vecpersonnages.toarray()); //listeobjets.setlistdata((personnage[]) vecpersonnages.toarray()); /*the last line gives me classcastexception (java.lang.object    cannot cast personnage.personnage)*/ 

use overloaded method of toarray(), toarray(t[] a);

personnage[] array = new personnage(vecpersonnages.size()); vecpersonnages.toarray(array); // fill array listeobjets.setlistdata(array); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -