Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different bg colors for JTable alternate rows - urgent

 
cs sakthi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Could any body help with code snippet for rendering the alternate rows background with different colors using Jtable, for eg.,
row 1 bgcolor - red
row 2 bgcolor - green
row 3 bgcolor - red
row 4 bgcolor - green and so on...
Thanx,
Ever Yours,
sakthi.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create your own cell renderer. Extend DefaultTableCellRenderer and override the getTableCellRendererComponent() method. Check what row the cell is in and set the background color to what you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic