954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to change color of a row

I want to change the color of the whole row("which is containing different data types in different cells") depending upon the value of one column. Have any idea?????
Please help!!!!!!!!!!!!!!!!!!!!!!!1

chankya
Newbie Poster
6 posts since Jan 2008
Reputation Points: 10
Solved Threads: 1
 

a row and a column of what? a table on a jsp page? in a jTable?
what do you want and what have you tried so far? it's no use for us to try sollutions that have allready proven to you not to work.

stultuske
Posting Sensei
3,110 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 432
 

Create your own custom TableCellRenderer, then set the background color of whatever the component is that you're returning for rendering.

Component c = whatever your component is
(rowIndex %2 == 0) ? c.setBackground(Color.blue) : c.setBackground(Color.white);


If you do this, you'll also have to control the highlighting of when the row is selected, which is easily handles in the same renderer class. The funny statement above is just an IF ELSE statement simplified. It basically says: IF row is an even number, color it blue, ELSE color white.

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You