aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes changing text color in cell 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 "changing text color in cell" Watch "changing text color in cell" New topic
Author

changing text color in cell

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
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


java amateur
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Feb 08, 2004
Posts: 1281
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

Joined: Jun 09, 2003
Posts: 4632
change the renderer of my previous example to this

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changing text color in cell