wood burning stoves
The moose likes Swing / AWT / SWT and the fly likes Custom Cell Renderer for JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Custom Cell Renderer for JTable" Watch "Custom Cell Renderer for JTable" New topic

Custom Cell Renderer for JTable

Abhin Balur

Joined: Feb 18, 2008
Posts: 21

I am using JTable for the fisrt time. I have a problem in rendering specific JTable cell. Here is what i am doing. I have a window(JFrame class) with a calendar on it. Calendar is implemented using JTable. When the user selects a date and chooses to set reminder another window(Reminder class) opens to set reminder. After he types in his reminder note and presses "OK" i want that particular date to be of some color. I am passing reference of the Jtable to the reminder window and the below code is what i am doing in the Reminder class to set the color for that cell but it is not workin out.

Here is the code:-

This is how i am installing the custom cell renderer in the Reminder class:-

MyCellRenderer renderer = new MyCellRenderer();
remtable.setDefaultRenderer(Color.class, renderer);

- remtable is the passed reference

This is my MyCellRenderer class:

class MyCellRenderer extends DefaultTableCellRenderer {

public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column)


Component renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

return renderer;


Would appreciate some quick responses.

Thank You.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Is your column class really "Color"? For a calendar I'd have expected something that can be displayed as numbers (indicating the dates).
Abhin Balur

Joined: Feb 18, 2008
Posts: 21

I am so sorry, i forgot to change that line and add some more to the description.

Here are the changes:-

that line is as follows:-

remtable.setDefaultRenderer(remtable.getColumnClass(remtable.columnAtPoint(q)), renderer);

As you can see above i am using Point q. This Point is also passed to this Reminder class to get the column class as shown in the line of code above.

Is it this that is creating the problem?

Abhin Balur

Joined: Feb 18, 2008
Posts: 21

Waiting for replies. If any doubt in understanding my question please ask me.

Thank You All.
I agree. Here's the link: http://aspose.com/file-tools
subject: Custom Cell Renderer for JTable
It's not a secret anymore!