Click to See Complete Forum and Search --> : insertColumn in a JTable?


Lars
August 11th, 1999, 10:43 AM
Hi,
i need a Function for columns like DefaultTableModel.insertRow(). I think there is no. Does someone
knows a workaround?

By, Lars.

varbsjava
August 12th, 1999, 07:45 AM
There is nothing like that in TableModel.
But u can use the JTable's methods addColumn(TableColumn) and moveColumn(int,int);

addColumn(TableColumn) will add a column at the end table. After that use moveColumn(int index, int target) to move your column where u want to be.

I hope this will solve yours.

regards,
arun...

unicman
August 12th, 1999, 08:11 AM
Well there may be another way, if u have sub-classed 'AbstractTableModel'.

U can make the sub-class work for dynamic columns. Here u just need to design the class such that,

1. getColumnCount method returns the number of columns u want
2. then other methods will reflect the change according to the number of columns.

After u change the number of columns u just need to repaint the JTable.

- UnicMan
http://members.tripod.com/unicman