views:

50

answers:

1

I am setting the renderer of a JTable using setDefaultTableRenderer.

JTable table = new JTable();
table.setDefaultRenderer(Object.class,MyRenderer);

MyRenderer extends DefaultTableCellRenderer and overrides paintComponent and getTableCellRendererComponent.

I have 4 rows and 8 columns and for strange reason my renderer methods are not called for first two columns of the first row.I use the SwingUtilites.invoke methods to call my GUI and its working for all other columns except these two columns.

+1  A: 

Without seeing your code I only can guess, but I think you probably have your own TableModel, which returns column.class for each column. JTable has DefaultCellRenderer for some of those classes, like Integer, etc. So probably your first columns are Integer columns, which results in JTable using its own renderer.

To avoid this, you just have to override the Integer.class renderer:

table.setDefaultRenderer( Integer.class, myRenderer );
ymene
you are right thanks
Harish