Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

changing text color in cell

 
Ranch Hand
Posts: 1282
  • 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
 
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: 1282
  • 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: 1282
  • 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
 
There's a way to do it better - find it. -Edison. A better tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!