Extending JTable through codes, adding objects into the cell


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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.