This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
When I attempt to add columns and headers to my dynamic table, I get no errors, but then again I get nothing showing up as a table either. However if I define some inital dummy columnNames in the String array within the model, it adds columns, but they are all of the same header. What is my basic problem or misunderstanding? I'm not sure if I have included enough code snippets below, if not, let me know and I will supply, otherwise that may be part of the problem. Appreciatively, Gary
Problem not fixed, but I did discover that I was using the wrong indexer for the 'for' loop. Now I'm getting an array index out of bounds on the TableColumn tc = tcm.getColumn(i); This is where I think I am misunderstanding the requirement. How do you do a getColumn on something that doesn't exists, but yet it is needed to add the column?
I was just going through my notes (I haven't worked with Swing lately) and found that it was more complicated then I thought. I ended up having to create a subclass of AbstractTableModel. This was for a JavaUnzip utility similar to WinZip. Here is the code for the AbstractTableModel class:
To use this I did this (zipTable is a JTable): zipModel = new ZipTableModel(); zipModel.setTableColumns(zipTable); zipTable.setModel(zipModel); and then after the user selects a file to unzip: File f = fileChooser.getSelectedFile(); zipData.setArchiveData(f); zipTable.tableChanged(new TableModelEvent(zipData)); I hope this helps. By the way, I got most of this code from the O'Reilly Swing book.