Ted
Ted

Reputation: 639

Java Swing set color of rows and columns based on index with defaulttablemodel

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.

Upvotes: 0

Views: 1123

Answers (1)

camickr
camickr

Reputation: 324098

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.

Upvotes: 1

Related Questions