|
-
October 25th, 2011, 12:09 PM
#1
jTables and models
Hi everyone! I need some help
I have a jTable that uses a model for handling data
tableModel = new DefaultTableModel();
jTable1.setModel(tableModel);
Then, in another class, depending of the class, I erase all the content of the model (and the columns)
public static void clearDefaultTableModel(DefaultTableModel tableModel) {
tableModel.setRowCount(0);
for (int i = 0; i < tableModel.getRowCount(); i++) {
tableModel.removeRow(i);
}
String[] vector = null;
tableModel.setColumnIdentifiers(vector);
}
When it comes to fill the table, I create the identifiers or columns and insert row by row
Object[] columnNames = {"header 1","header 2","header 3"};
tableModel.setColumnIdentifiers(columnNames);
....
String[] vector = {string1,string2,string3};
tableModel.addRow(vector);
What I need is put the jTable not editable (I already changed the seteditable property of the table) and most important, when its time to recreate the model, put differents widths to each column (I dont want the ID column with the same width as the name column)
Hope you can help me, tables and models are confusing me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|