Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 31st, 2007, 04:57 AM
Authorized User
Join Date: Jul 2006
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to change the colour of a cell in a jtable

Can someone show me the way of changing the background color of an specific cell(say (5,5)) in a jTable.
I`ve read a lot about cell renderers but all I could find is how to change the colour of a complete row or coloumn.

I will appreciate very much the help.


Old April 25th, 2007, 03:35 AM
Friend of Wrox
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post

I haven't worked on JTable but for your problem i think, we dont have a direct solution, what you can do is implement the TableCellRenderer interface or extend DefaultTableCellRenderer class and override the method getTableCellRendererComponent() place the condition for which you want to render the cell differently.
delcare two private variables to store row and column values and a method to update these values, place a condition in the getTableCellRendererComponent() method to compare the row and column values of the member variables and row column values passed to the getTableCellRendererComponent() method if they are equal highlight the row or display normally. Trade of to this solution is you've to call the method to update the row column values in the cellrenderer object and refresh the table to get the changes reflected on UI.

Hope its usefull to you.

Following links have few examples related to it, these might help you solve your problem.

The following link has an example which addresses a problem it is very much similar to yours try looking at this one



Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:Gridview Change Colour ashvinm ASP.NET 2.0 Basics 1 March 4th, 2008 09:19 AM
Row colour change with Checkbox Toiletbrush Infopath 3 July 10th, 2007 06:25 AM
How do I change a row colour with a checkbox? Lucy Javascript How-To 4 November 15th, 2005 08:53 AM
JTable Cell Renderer dontknowmuch Java GUI 1 August 3rd, 2005 10:28 AM
change the colour of some particular rows bimal ADO.NET 1 September 10th, 2004 02:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.