Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable cell rendering

 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic