/* 3magic Coffee Table Tutorial 3 Tutorial3.java - Customizing the GridPanel with GridAttributes. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.applet.*; import CoffeeTable.Grid.*; public class Tutorial3 extends Applet { public void init() { // Instantiate a new Grid Panel with 10 rows and 5 columns // and other defaults like cell selection, row and column headers, // row and column lines enabled and with scrollbars. int numRows = 10; int numCols = 5; GridPanel grid = new GridPanel(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(400, 200); // SETUP ATTRIBUTES FOR THE ENTIRE GRID: // Let's use Times, plain, 9-point. Font gridFont1 = new Font("TimesRoman", Font.PLAIN, 9); // Set the text color to blue. Color textColor1 = new Color(0, 0, 255); // Set the background color to light yellow. Color bgColor1 = new Color(255, 255, 200); // Set the flags for left justificationa and automatic string truncation. int gridFlags = GridPanel.JUST_LEFT | GridPanel.TRUNC_STRING; // Assemble the attributes. GridAttributes gridAttr1; gridAttr1 = new GridAttributes(grid, // Pass in a reference to the grid. gridFont1, // The desired font. textColor1, // The color of the text. bgColor1, // 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); // SETUP ATTRIBUTES FOR THE GRID HEADERS: // And do it all in one line of Java... grid.setHeaderAttributes(new GridAttributes(grid, new Font("Courier", Font.BOLD, 12), null, null, 0, 0), true); // SETUP ATTRIBUTES FOR COLUMN 3: // Override the text color and justification, inherit rest from grid attributes grid.setColAttributes(3, new GridAttributes(grid, null, Color.red, null, GridPanel.JUST_RIGHT, 0), true); // SETUP ATTRIBUTES FOR ROW 4: // Override the background color and justification, inherit rest from grid attributes grid.setRowAttributes(4, new GridAttributes(grid, null, null, new Color(200, 255, 255), GridPanel.JUST_RIGHT, 0), true); // Add the grid into the applet panel add(grid); // Add some data for display. for (int col=1; col<=numCols; col++) { grid.setColHeaderText(col, "Column " + col, true); for (int row=1; row<=numRows; row++) { grid.setCellText(col, row, col + ", " + row, true); } } } }