File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Comparing JTable cells Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Comparing JTable cells" Watch "Comparing JTable cells" New topic

Comparing JTable cells

Frederick Pease

Joined: Aug 12, 2013
Posts: 3
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

Joined: Sep 13, 2007
Posts: 3132

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:

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
I agree. Here's the link:
subject: Comparing JTable cells
jQuery in Action, 3rd edition