• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically redrawing columns in TableViewer

 
J Arshad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does anyone know how to reset column names, properties, etc dynamically. For instance, my application allows the user to add rows as well as columns. When a new row is added to the input, it appears in the table viewer upon refresh(). But what do I have to do to force a new column to appear when the user chooses to add one.

Currently, I'm doing these steps:

1. Making a call to TableViewer::setColumnProperties() with the new column names.
2. Reformatting TableViewer::getTable() to include new columns.
3. Resetting TableViewer::setCellEditors() to create the correct number of editors as a result of adding a column.

But having no joy with this:-(. If I step through the code, it has the new column name both in table viewer's properties as well in the column names of TableViewer::getTable(), but it just wouldn't redraw the table.

Have spent too much time on this. Any help would be greatly appreciated!

Jay
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The general approach is to add the column or row to the TableModel, either an AbstractTableModel or its subclass DefaultTableModel, and then tell the model to update itself using methods available in each api. The JTable api has methods for setting default editors and renderers based on class type. Or you can add a specific editor or renderer to each new column as you add it to the model.
 
J Arshad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I'm actually using SWT and not Swing. So setInput() is the way you would pass a model to the table ad then render it using an ITableLabelProvider implementation.

My problem lies in the fact that I'm able to change rows dynamically (adding a new row is adding another data set to the model). But adding a new column seems to be different. Even though the model has all the right columns in the memory (after adding), the actual table doesn't get refreshed/redrawn. I have tried TableViewer::refresh() as well as TableViewer::getTable().redraw().

So if anyone has done this in SWT, it'd be a great help.

Jay.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic