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
5 Answers
JTable know two kinds of 2D Arrays Object [][] or Vector<Vector<Object>> that are directly accesible, some examples about JTable
2 Comments
DefaultTableModel?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.
2 Comments
...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());
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.
Comments
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.