// JP opened flex table

Click to See Complete Forum and Search --> : add column in a DefaultTableModel


andrepr
February 5th, 2002, 01:44 PM
Hi Gurus!

i´m tryng do add a column in a DefaultTableModel, it works. but when i try to change the MaxWidth, MinWidth e PreferredWidth it doesñ´t work..
my question is:

How can i add columns, change attributes in this columns and update, delete, insert Rows in the table using a DefaultTableModel ?

thanks !!!

dlorde
February 6th, 2002, 09:19 AM
It works OK here... I add a column like this:String colName = "New Column";
String[] colData = { "Row 0", "Row 1", "Row 2", "Row 3"};
DefaultTableModel dtm = (DefaultTableModel)myTable.getModel();
dtm.addColumn(colName, data);

I change the column width like this:myTable.getColumn(colName).setMaxWidth(newMaxWidth);
...
myTable.getColumn(colName).setMinWidth(newMinWidth);

To add rows to a DefaultTableModel call DefaultTableModel.addRow(...) or to insert, call DefaultTableModel.insertRow(...). To delete rows use DefaultTableModel.removeRow(...). To update a row, either delete it and insert an updated version, or update every cell in the row using setValueAt(...) for each cell.

You might find the JavaDocs helpful: http://java.sun.com/j2se/1.4/docs/api/index.html.

Dave

//JP added flex table