This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable Color Change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Color Change" Watch "JTable Color Change" New topic

JTable Color Change

Prakash Radhakrishan

Joined: Jun 27, 2000
Posts: 3
1. How do I put different colours in different rows like first row red color, second row blue and so on....and how to do the same thing but with individual cells of a JTable.
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
hi prakash,
to play with colours u need to add a renderer to ur table. the code goes like this.
JTable myTable = new JTable(.....);
first of all u need to write a renderer class example is
class gridTableCellRenderer extends JLabel implements TableCellRenderer{
/// inside getTableCellRendererComponent function write all
/// the color things u want
public Component getTableCellRendererComponent( JTable table,
Object value, boolean isSelected,
boolean hasFocus, int row, int column )
if(row == 2)
if(row == 4 && column == 1)
////add renderer for every type of colunms
//// that is if u have one column of type JLable, & other of type
/// Integer then u'll write
myTable.setDefaultRenderer(JLabel.class,new gridTableCellRenderer());

hope this helps
Prakash Radhakrishan

Joined: Jun 27, 2000
Posts: 3
Hi deekasha gunwant,
Thank You for the response. It works fine.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: JTable Color Change
It's not a secret anymore!