javaswingjtablebeans-binding

Bind arraylist to jtable


recently I wrote a C# application, that simply rendered the elements of a list ( named lst) of objects into a table, with the following code:

DataTable dt = Request.ListToDataTable(lst);
dw = new DataView(dt);
dw.Sort = "columnb ASC";
dataGridView1.DataSource = dw;

now i need to do something similar in java : is it possible? or i have to create a tablemodel and working with it? Let's say I've a list of Person objects, and I want to build a table containing surname, name and age. Is it possible to do it in a smart way ?


Solution

  • or i have to create a tablemodel

    Yes you will need a custom TableModel.

    You can use the Bean Table Model which allows you to create the model and the table in two lines of code.