Add columns dynamically to a JTable

Hi everybody!

I know there's been a lot of discussion on this subject but the examples I found are yet a little complex for me and I couldn't make my program work as I expect.

What I have is a JTable that uses a custom table model which extends form DefaultTableModel. This model has one constructor which has a few columns already set when the application starts and another constructor with the amouont of dynamic columns to be added. Then I also have a combo box which values determine the information to be displayed in the table. When the combo box changes the information in the table is updated (cleared and refilled). I'm adding new columns to the table through the model usign the second constructor, then I re-set the table model for my table using setModel(model) method with the new columns in it. I tried using the fireTableStructureChanged() method, fireTableDataChanged() method and even updateUI() method but I couldn't get my new columns displayed in the table. Is something wrong or missing in this procedure?

Ah! to add columns to the model I'm using a Vector collection.

Thanks in advance

[1146 byte] By [mmarassoa] at [2007-11-27 10:31:22]
# 1

> Is something wrong or missing in this procedure?

Can't tell what you are doing based on a verbal description.

Check out this posting for a working example:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5166643

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

camickra at 2007-7-28 18:09:10 > top of Java-index,Desktop,Core GUI APIs...