JTables and dynamically adding data

M

michael.miceli88

Hey,
I have a JTable that I want to add a new column to every time someone
clicks a button. I have been reading about extending the
AbstractTableModel, but I don't how this allows you to add a new
column. The examples online show what happens when a user edits a
table, but I don't want that. I want it add when the user presses a
button outside of the table. Some advice would be appreciated.

Thanks
 
M

michael.miceli88

Have you tried incrementing the value returned by your getColumnCount(),
making sure getValueAt() now returns the appropriate values then calling
fireTableStructureChanged()?

No, but I will give this a try, and hopefully get back to you by the
end of the day.
Thanks
 
R

Roedy Green

The examples online show what happens when a user edits a
table, but I don't want that. I want it add when the user presses a
button outside of the table. Some advice would be appreciated.

You would have to both modify your TableModel to add the data, and
tell the GUI JTable part you have a new column. You would add it just
the way you would add a column to start.

See http://mindprod.com/jgloss/jtable.html
 
C

Chase Preuninger

every time you want to change it just create a new model and use the
setModel function in the JTable class to update the UI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top