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

5 Answers 5

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

+1 Is this characteristic of the DefaultTableModel?
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 :-)
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.

2 Comments

ArrayList<String > arl = new ArrayList<String >();.....Object obj = arl.clone();.... final JTable table = new JTable(data, obj); give an error
@KIRAN: I don't understand your code. What error? You might update your question with an sscce; code in comments is hard to read. I see both @camickr and @Catalina Island addressed your binding question.
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());

2 Comments

how to access the datas from row and colums.how to bind it?
how to bind arraylist to JList?
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.