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:
Easy

Other People Are Reading

Instructions

  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

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

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