Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable row colour(urgent)

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i want to set the color of 2nd row.
i am using TableCellRenderer to make display a particular row in a different colour.the code seems to work fine but the colour seems to be changed for all the rows after row 2.even if i set the color of that particular row.i am using defaultTableModel.any clue where i am doing wrong
any help will be appreciated
Regards
Simon
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out this article at JGuru:
http://www.jguru.com/forums/view.jsp?EID=521888
Cheers,
Julia
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The key is to remember that the table cell renderer is called for every single cell in the table, not just the selected cell(s). When I've had problems of this nature in the past it's always been a misunderstanding of this key point.
Let's look at the method

You would write a class that implements this method (which is what it sounds like you've done). Be sure that you're checking the row int to see if you need to do any special handling of a particular row. You're problem may be as simple as code that says if (row>2) instead of if(row==2).
I know that's a very generic answer, but I hope it helps. If not then let's see your source code and maybe we can figure it out from there.
 
The City calls upon her steadfast protectors. Now for a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic