jQuery in Action, 2nd edition*
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 Android Security Essentials Live Lessons this week in the Android 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 http://www.javaranch.com/name.jsp . 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 frankcarver.me ~ 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.

wood burning stoves
subject: To set color for rows in JTable
Similar Threads
Color in JTable
JTextArea Alternate Row color Change
How to Set the JTable Rows Color??
how to solve this simple problem in jstl ?
Weirdness with JSTL and Style Sheets