Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing JTable cells

 
Frederick Pease
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to compare two JTabel cells in the same row, then whichever number is higher in the cell, set that cell's background color green, and the other red?
This is how my table looks right now:
 
K. Tsang
Bartender
Posts: 3504
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Are you using a TableModel to fetch your data? For the cell background color, a cell renderer will do the trick.

Depending on how you set up your classes/data, you may just do something like:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic