Question

I want to be able to do two things:

  1. set colors of rows based on index, so first row is red, second blue, third green
  2. be able to set color of columns also based on something, be it index or their names etc, whatever is possible.

I do not need to detect selection change or anything. Could someone tell me how to do that? What methods would help etc? In case the title wasn't read, this is regarding DefaultTableModel in JTables.

Was it helpful?

Solution

set colors of rows based on index,

Table Row Rendering might give you some ideas.

be able to set color of columns also based on something

You can provide a custom render for any column. Then you can add you logic to color the column based on something. Read the JTable API and follow the link to the Swing tutorial on How to Use Table and you will find a section on creating a custom renderer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top