• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable: How to get the cell as a component for a given position  RSS feed

 
Yosuf Ibrahim
Ranch Hand
Posts: 128
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I made an interactive Calendar as JTable, however, I would like to change the background colour for some of the cells based on data I have. I figured out how I can get the position of the cell I need to edit but I have no idea how to get the cell at that position as a component so I can edit the cell background and foreground.

So basically I have the (x,y) position of the cell. I need to use that and get the cell to change its background colour.

Thank you

 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't change the cell component directly, you use a TableCellRenderer for that. The easiest way to create one is to extend DefaultTableCellRenderer and override getTableCellRendererComponent:

You still have to set it on the JTable. The official way to go is to call setDefaultRenderer for each class you have in your table, or set it as the renderer for each column separately.
 
Rob Camick
Ranch Hand
Posts: 2828
15
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!