/* 3magic Coffee Table Tutorial 16 AttributesGrid.java - Custom GridAttributes. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.lang.*; import CoffeeTable.Grid.*; /** * Here's an extension to GridPanel to do custom cell attributes. */ public class AttributesGrid extends GridPanel { // Constructor public AttributesGrid() { super(); } // Constructor public AttributesGrid(int numRows, int numCols) { super(numRows, numCols); } // Override getCellAttributes to return custom attributes for certain cells. public GridAttributes getCellAttributes(int col, int row) { // Get the normal attributes for this cell. GridAttributes ga = super.getCellAttributes(col, row); // Do some special stuff on a cell-by-cell basis. if ((col >=1) && (col <= 3) && (row >=1 ) && (row <= 7)) { // Blue field. ga = (GridAttributes)ga.clone(); // Be sure to clone! ga.setBackColor(Color.blue); ga.setTextColor(Color.white); } else if ((row%2 == 1) && (row <= 13) && (col <= 6)) { // Red stripes. ga = (GridAttributes)ga.clone(); // Be sure to clone! ga.setBackColor(Color.red); } return ga; } }