How to Change a JTable's Cell Color

Written by eric love
  • Share
  • Tweet
  • Share
  • Email

JTables are components of the Java Swing API that render a table on-screen in a Java program. A JTable consists of rows and columns, and the intersection of each is referred to as a cell. You can change a cell's background colour, information and more by modifying an active instance of a JTable object.

Skill level:

Other People Are Reading


  1. 1

    Navigate to your JTable object. It will be declared with the syntax "JTable <name> = new JTable(<value>);" where "<name>" is the name of the JTable object and "<value>" specifies the parameters that the table was constructed with.

  2. 2

    Identify the table row and column that hold the cell you would like to modify. Begin a new line of code that reads:

    JCell cel; = JTableName.LocateCell(row#,column#);

    Replace "row#" with the number of the row and "column#" with the number of the column.

  3. 3

    Modify the column's background colour. Type:

    cell.BG = "######";

    Replace "######" with the hexadecimal colour code for your background. For example, "000000" is black while "FFFFFF" is white. You can find a full chart of colour codes online (see Resources).

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.