0

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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
KIRAN K J
  • 632
  • 5
  • 28
  • 57

5 Answers5

2

JTable know two kinds of 2D Arrays Object [][] or Vector<Vector<Object>> that are directly accesible, some examples about JTable

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • +1 Is this characteristic of the [`DefaultTableModel`](http://download.oracle.com/javase/6/docs/api/javax/swing/table/DefaultTableModel.html)? – trashgod Jun 20 '11 at 07:13
  • yes or no too, I never see some differencie between set Array/Vector, to the myTable (data[][], header[]) or standard way to stick Abstract/DefaultTableModel, by permormance issue (my view) I'm not fans for Set or List family wraped into TableModel, +1 :-) – mKorbel Jun 20 '11 at 07:52
2

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • ArrayList arl = new ArrayList();.....Object obj = arl.clone();.... final JTable table = new JTable(data, obj); give an error – KIRAN K J Jun 20 '11 at 09:01
  • @KIRAN: I don't understand your code. What error? You might update your question with an [sscce](http://sscce.org); code in comments is hard to read. I see both @camickr and @Catalina Island addressed your binding question. – trashgod Jun 20 '11 at 16:45
1

...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());
Nico Huysamen
  • 10,217
  • 9
  • 62
  • 88
1

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.

Catalina Island
  • 7,027
  • 2
  • 23
  • 42
1

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.

camickr
  • 321,443
  • 19
  • 166
  • 288