• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamically redrawing columns in TableViewer

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic