dcsimg
Using Custom Cell Renderers on JTable
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Effi_Olivkovich
Posted On:   Wednesday, July 4, 2001 03:02 AM

I'm Extending a JTable. I created a cell renderer. When I'm trying to attach the renderer to a column using the following line: TableColumnModel tblColMdl = this.getColumnModel(); tblColMdl.getColumncolIndex).setCellRenderer(new CurrencyRenderer()); the table does not use this cell renderer. I tried the following code: this.setDefaultRenderer(Double.class, new CurrencyRenderer()); and it worked. I need to attach a renderer for each individual column, and not for a group of columns. can anyone tell me why the first set of code does not work?    More>>

I'm Extending a JTable.
I created a cell renderer.
When I'm trying to attach the renderer
to a column using the following line:


TableColumnModel tblColMdl = this.getColumnModel();
tblColMdl.getColumncolIndex).setCellRenderer(new CurrencyRenderer());




the table does not use this cell renderer.

I tried the following code:


this.setDefaultRenderer(Double.class, new CurrencyRenderer());



and it worked.

I need to attach a renderer for each individual column, and not for a group of columns.

can anyone tell me why the first set of code does not work?

   <<Less

Re: Using Custom Cell Renderers on JTable

Posted By:   Johan_Karlsson  
Posted On:   Thursday, July 12, 2001 11:12 PM

I use the following code:


// Set custom cell renderers:
TableColumnModel columnModel = getColumnModel();
setAutoCreateColumnsFromModel(false);

TableColumn column = columnModel.getColumn(0);
column.setCellRenderer(new TimeCellRenderer());

for(int columnNo=1; columnNo < 8; columnNo++){
column = columnModel.getColumn(columnNo);
column.setCellRenderer(new ScheduleCellRenderer());

// Create one new TableCellRenderer for each column
TableCellRenderer tcrDefault = new JTableHeader().getDefaultRenderer();
column.setHeaderRenderer(tcrDefault);
}
About | Sitemap | Contact