/* 3magic Coffee Table Tutorial 16 Tutorial16.java - Custom GridAttributes for individual cell colors. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.applet.*; import CoffeeTable.Grid.*; public class Tutorial16 extends Applet { public void init() { // Instantiate a new overridden Grid Panel // and other defaults like cell selection, row and column headers, // row and column lines enabled and with scrollbars. int numRows = 13 + 10; int numCols = 6 + 10; AttributesGrid grid = new AttributesGrid(numRows, numCols); // Be sure to set the preferred size if you are using it in a // layout that resizes based on preferred size. grid.setSize(450, 350); // Columns and Rows. int widths[] = {70, 70, 70, 70, 70, 70}; grid.setColWidths(widths, true, true); grid.setRowHeight(20); // Show the row headers. grid.setRowHeaderWidth(25); grid.setRowNumbers(true); // SETUP ATTRIBUTES FOR THE ENTIRE GRID: // Set the flags for left justificationa and automatic string truncation. int gridFlags = GridPanel.JUST_CENTER | GridPanel.TRUNC_STRING; // Assemble the attributes. GridAttributes gridAttr1; gridAttr1 = new GridAttributes(grid, // Pass in a reference to the grid. null, // The desired font. null, // The color of the text. null, // The color of the background. gridFlags, // Additional attribute flags. GridPanel.TEXT); // The cell type. // Set up attributes for *ALL* the cells in the grid, grid.setGridAttributes(gridAttr1, true); // Add the grid into the applet panel add(grid); // Add some stars for display. for (int col=1; col<=3; col++) { for (int row=1; row<=7; row++) { grid.setCellText(col, row, "* * *", true); } } } }