Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Cell Renderer for JTable

 
Abhin Balur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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);

renderer.setBackground(Color.RED);
renderer.setForeground(Color.BLUE);
return renderer;

}}

Would appreciate some quick responses.

Thank You.

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

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?


THanks
 
Abhin Balur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Thank You All.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic