Reputation: 732
i have an arrylist and a list view.i need to bind the arraylist to listview. is there 2 dimensional arraylist in java. if so,how to bind datas in arraylist.How to bind it in a JTable
Upvotes: 0
Views: 4312
Reputation: 10427
...is there 2 dimensional arraylist in java... - Yes
// T is the type of your data.
List<ArrayList<T>> list = new ArrayList<ArrayList<T>>();
UPDATE
To use the data from the ArrayList
in the JList
you need to convert it to an array of objects. For example:
JList jlist = new JList(list.toArray());
Upvotes: 1
Reputation: 324197
I don't know what a "listview" is. But if you want to display data from an ArrayList in a JTable then you need to create a custom TableModel. List Table Model is one implementation that you can use.
Upvotes: 1
Reputation: 7136
how to bind it in listview
JList
has a AbstractListModel
that works a lot like how JTable
has a AbstractTableModel
. If that's what you want, the examples in "How to Use Lists" may help.
Upvotes: 1
Reputation: 205875
Java supports multi-dimensional data structures such as List<List<…>>
. ArrayList
is just one implementation of the List
interface, and each dimensions may use a different implementation. This example illustrates List<List<Integer>>
.
The two dimensional case may require nothing more elaborate than List<Record>
, shown here; or List<Value>
, shown here in the context of an AbstractTableModel
. See Creating a Table Model for additional details.
Upvotes: 2