• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing text color in cell

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have this jTable and want cells that verify a certain condition to appear in red; to do that, i have this code:

and in the panel that houses my table, i have:


what happens is diferent from what i expected: many cells appear in red, even if they dont fit the pre condition; more: if i use the mouse, the red color eventually propagates to all cells

my cells are all strings

how can i get this right?

TiA
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the look of it, you need to include an 'else'

here's a simple demo of highlighting cells with a value < 3
run it, see it working, then comment out the 'else' and rerun

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot!

i was experimenting, and missed just by the keyword else
it does work nicely!

as an aside, i'm trying to right align my 2nd column, and in jtable constructor, i have:
, but i get both columns right aligned

can you help me, please?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change the renderer of my previous example to this

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in case someone else is interested in having doferent colors in cells depending on logic over database values, or align values in columns or alternate colors in table's background, here's my code, thanks to Michael
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic