| | | | Browse by category |
Question
How to change the font and color of a single cell or entire row in the Gantt Table?
Answer
There is no direct mechanism for this, although it can be accomplished with a few APIs.
To change the color or style of a single cell in the Gantt table, you can create a custom []TableCellRenderer[
] by subclassing []TableCellRenderer[
] and overriding its getTableCellRendererComponent()
method. Then you can set the custom []TableCellRenderer[
] on an individual column to apply to one or more cells within the column.
If you want to apply a style to individual rows, you need to set the custom renderer to each and every column, with the renderer applying the appropriate style for the correct rows in each column.
For example, the following sample code sets a custom []TableCellRenderer[
] with the wheat/plum/Times Roman style for rows 3 and 4 in the "Name" column:
IlvJTable table = chart.getTable();
TableColumn nameColumn = table.getColumn("Name");
nameColumn.setCellRenderer(new MyTableCellRenderer(nameColumn.getCellRenderer(),
3, 4,
IlvColorUtil.getColor("wheat"),
IlvColorUtil.getColor("plum"),
new Font("Times Roman", 0, 16)));
To apply this to every cell in the row, you would iterate this call over all of the columns:
int count = table.getColumnCount();
for (int i = 0; i < count; i++)
{
TableColumn column = table.getColumn(i);
if(column != null)
column.setCellRenderer(new MyTableCellRenderer(column.getCellRenderer(),
3, 4,
IlvColorUtil.getColor("wheat"),
IlvColorUtil.getColor("plum"),
new Font("Times Roman", 0, 16)));
}
The attached sample includes the detail implementation of the MyTableCellRenderer class and illustrates this technique: setTableColorRow.zip
Note : In order to run the sample with JViews 8.8, you need to include icu4j-4_8.jar in addition to jviews-framework-all.jar and jviews-gantt-all.jar files in the classpath. icu4j-4_8.jar is located in the JViews Framework libexternal
directory. However, to run the sample with JViews 8.6 and below, you need to comment out the call to the method ilog.views.util.IlvProductUtil.DeploymentLicenseRequired (line 452 in setTableColorRow.java). You do not need to include icu4j-4_8.jar.