Extending JTable through codes, adding objects into the cell

Hi,

I need to write a piece of code that add row of information into a table whenever the user click  button "Add person" after entering some information. E.g. User enters name, id of a person, and when click, name, id of the person gets entered into Column A and Column B in a new row.

In Column C, I then need to programatically add a checkbox for the user. When the user click on the checkbox, the whole cell will turn green, and if the checkbox is unclicked, the whole cell will turn red.

If user click on "Add Device", then the columns in the table will added by one, and all the rows in the table will get a new cell, with a checkbox added into it.

I'm not familiar with Swing, AWT. Can someone help me with how to write this code?

Thanks!!
amaiAsked:
Who is Participating?
 
hoomanvCommented:
the table structure (rows and columns) is defined in two interfaces one is TableModel and the other is TableColumnModel. for your job its better to use new JTable(DefaultTableModel). DefaultTableModel is derived from TableModel which supports Vectors of cell values so you can add new rows to it later. getColumnModel() gives you the table headers enables you to add new columns to table too.
and for the checkbox. there are to interfaces called TableCellRenderer and TableCellEditor which enables you to have any thing you want to be shown in a cell and any way you like the user edit a cell interactivly.
please refer to sun's java tutorial and read the samples to learn how customize your table
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.