This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTable cell rendering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable cell rendering" Watch "JTable cell rendering" New topic
Author

JTable cell rendering

jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
Hi,

My code reads data from text file, the format of each line is below: ( a small sample text file would be...just 5 lines)
00
35
25
35
00

If you would think of each line as an address [0][0]; i'm interested in repetition of addresses and wish to show this with a JTable


So far the code runs fine, it prints the number of times any address show up in the text file on the JTable.

Now i must switch to using color intensity to show repetition. (because the real text file is about 64, 64 array)

How do i shade each cell from white to red as they get more hits.









Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Most of that code is irrelevant to your question. You're asking how to make a JLabel's colour shade from white to red depending on some parameter. White meaning zero, I suppose, and red meaning the maximum value. That's all. All of the JTable background is unhelpful.

So do you have a question about how to find the maximum value? Or just how to choose a colour value which is 0.693 of the way between white and red? Or some other question as well?
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
thank you,

I am asking how to make a "cells" color get darker based on parameters. Not a JLabel, but the color of the cell itself.


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

You are using a JLabel, you know. DefaultTableCellRenderer extends JLabel. But in any case the answer to that is easy: you call the setBackground(Color) method. Make sure there is a background colour to set by also calling setOpaque(true).
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable cell rendering