JTable - Changing a cell's background color

Hello,

I'm using a JTable and I need to, when a button is pressed, change a certain cell's color. The whole table's background color is gray and it's cells display ImageIcons. I got the Icons part up and running but I'm having great trouble on changing a cell's color - so far I've only managed to change a whole column and that's not what I need. I've been Googling for solutions for 2 hours and reading it's results for 4, so I'm getting pretty desperate here :(

For doing what I stated, what I have so far for the button's mousepressed event  is:
    DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
    dtcr.setBackground(Color.green);
    jTable1.getColumnModel().getColumn(3).setCellRenderer( dtcr );

By the way, after I change the background color of a column I can't properly move an icon on to it (but that's probably because it changes the column's DefaultRenderer, I can change it back afterwards, right?). I believe, since I'm using ImageIcons on the cells I could create icons of the background color I desire and use setValueAt to change the cell's appearance -is this a solution? But anyway, I haven't gotten the icon to fully cover the cell yet...


Thanx in advance! :)



LVL 1
bass20Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nesnemisCommented:
0
bass20Author Commented:
Like I said, I've been Googling for a solution for 2 hours, I already had found and applied that and it didn't work or I couldn't apply it to my particular situation.
0
CEHJCommented:
>>I already had found and applied that and it didn't work

Please post that code
0
bass20Author Commented:
I appreciate all your help but I solved the problem using Icons - that way I don't have to go around changing DefaultTableCellRenderers, I just use setValueAt and place a colored icon on the cell I want.
If anyone has anything to add, you're welcome to do it :)
0
objectsCommented:
heres an example of what you need that may help:

http://www.objects.com.au/java/examples/swing/ColoredTableCell.do
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.