Article View: borland.public.jbuilder.java.swing
Article #1485How to permanantly set a custom CellRenderer to a jTable?
From: Zoran Pjevic
Date: Thu, 11 Dec 2003 14:36
Date: Thu, 11 Dec 2003 14:36
42 lines
2293 bytes
2293 bytes
Following situtation:
I am using a jtable with a custom tablemodel, custom cellrenderer.
The table displays dynamic data coming from an external source.
I attach the the cell renderer to the table and set up the columns
widths as follows:
MyTableModel tableModel = new MyTableModel();
JTable table = new JTable(tableModel);
JViewport tableViewport = jScrollPane_PcmTelemetry.getViewport();
tableViewport.add(table, null);
for (int i=0; i < table.getColumnCount(); i++) {
table.setDefaultRenderer(jTablePcmTelemetry.getColumnClass(i),
new MyCellRenderer());
}
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnModel tableColumnModel = table.getColumnModel();
for (int i=0; i < tableColumnModel.getColumnCount(); i++) {
tableColumnModel.getColumn(i).setPreferredWidth(35);
}
But then when new data comes the TableModel calls either
fireTableStructureChanged(), fireTableDataChanged() or
fireTableRowsUpdated(0, size-1)
depending on what has changed in the data.
After this I loose the CellRenderers and the Width of the Columns, ie.
there set back to the default ones.
How can I set a Custom Cell Renderer permanently or set the width of
the columns permanently so that they
will survive any of the previous mentioned events?
I'll be grateful for any help on this.
Regards,
Zoran
Technical Details
Message-ID:
<060htvg1iaeb9qm879m00ghf3c0ln89j5m@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e2f4c37672465914,start X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2003-12-11 06:39:52 PST From: Zoran Pjevic <zpjevic@anitesystems.de> Newsgroups: borland.public.jbuilder.java.swing Subject: How to permanantly set a custom CellRenderer to a jTable? Date: Thu, 11 Dec 2003 15:36:45 +0100 Message-ID: <060htvg1iaeb9qm879m00ghf3c0ln89j5m@4ax.com> X-Newsreader: Forte Free Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 213.157.29.250 X-Trace: newsgroups.borland.com 1071153300 213.157.29.250 (11 Dec 2003 06:35:00 -0700) Lines: 42 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail