Sunday, 15 July 2012

java - Why I cannot add ArrayList directly to Jlist? -


I am trying to add the orllist to the list, but the only way I understand this is to write the code like this. :

  array list & lt; String & gt; Label = new arreelist & lt; String & gt; (); Jellist Jellist = New Jellist (Labels. Toure ());   

It is confusing to me that why can not I just add an Arvelist directly to the jellist like this:

    

Thanks in advance.

"assistant" JList (and many inclined components) Consultants were meant to use the JList with simple data structures.

Used with models that provide real data in view.

Swing was included in the main library (earlier than JDK 1.3) and originally known before the collection API is presented, it is likely that the original developers have the "code" > List was not available to them (hence the inclusion of vector .

It seems that no one is fit to update the libraries (partially Because it can be decided that the original constructor is included Should not have been done, but I was not in that meeting;))

Make a better / simpler solution to create your own model which use the list as a data source Does.

For example ...

  Public category MyListModel & lt; T & gt; Expansion of AbstrailtDodel extension & lt; T & gt; {Private list & lt; T & gt; People; Public MyListModel (list & lt; T & gt; people) {this.people = people; } @ Override Public Ent Size () {return people.size (); } @overराइड सार्वजनिक टी लाट एलायमान (इंट इंडेक्स) {return people.get (index); }}   

Then you can only supply it to JList whenever you need it ...

  JList myList = New Jellist (New MistyTodel & lt; MyObaze & gt; (listOfMyObjets));    

No comments:

Post a Comment