File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes To set color for rows in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "To set color for rows in JTable" Watch "To set color for rows in JTable" New topic

To set color for rows in JTable


Joined: Jun 19, 2001
Posts: 6
Hi all,
Can any body help me in setting different color for rows. I have done it for column.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
In the DefaultCellRenderer this method
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
Gives both the row and column. Check the row and do what you would have for the column.

Joined: Jun 19, 2001
Posts: 6
Hi Paul,
I have to do it dynamically. How can i pass the row index so that i can check with the getTableCellRendererComponent method's row(int).
Once after creating the table, according to certain creteria i have change the color of the corresponding row.
Can help me in this issue.

I agree. Here's the link:
subject: To set color for rows in JTable
jQuery in Action, 3rd edition