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


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "set rows color in JTable" Watch "set rows color in JTable" New topic
Author

set rows color in JTable

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi.
I require to set the color of a row based on the value present in it. Suppose there are 3 columns col1,col2,col3 respectively and there are 2 rows as 1,2,3 and row 2 is 4,5,6
Now i need to set the color of the row to red when it contains the value 2. How can i do that some one help.


Thanks and Regards
alexander
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2944
    
    9

Are you using your own table model? If so, you should able to determine the data of the table cell and do the checking accordingly.


K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi.
I am using DefaultTableModel
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10733
    
    9

Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
I have tried following that tutorial but i am using default table model to get data from data base. The code is below some one please point out what changes shall i do.






Thanks in Advance
alexander>
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Thanks a lot guyz i have done it like this. If any more ideas please give me.

>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: set rows color in JTable
 
It's not a secret anymore!