• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTable cell rendering

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.









 
Sheriff
Posts: 28436
104
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 28436
104
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you.
 
There's a city wid manhunt for this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic