/* 3magic Coffee Table Tutorial 4 Tutorial4.java - User Interface features. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.applet.*; import CoffeeTable.Grid.*; public class Tutorial4 extends Applet { String colLabels[] = {"First", "Last", "Fruit", "Color", "Salary"}; String cellData[][] = { {"Ray", "Yoshi", "apple", "red", "$50,000"}, {"Neal", "Bajaj", "mango", "orange", "$60,000"}, {"Greg", "Finn", "kiwi", "green", "$90,000"}, {"Fred", "Mertz", "banana", "yellow", "$30,000"}, {"Ethyl", "Nertz", "blueberry", "blue", "$35,000"}, {"Lucy", "Ricardo", "cherry", "magneta", "$40,000"}, {"Ricky", "Arnaz", "coconut", "white", "$45,000"}, {"Jeremy", "King", "watermelon", "pink", "$15,000"}, {"Thumper", "Lapin", "grape", "purple", "$25,000"}, {"Seargent", "Argent", "blackberry", "black?", "$65,000"}}; 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.resize(400, 200); // Show the row headers. grid.setRowHeaderWidth(30); grid.setRowNumbers(true); // CONFIGURE RESIZING ------------------------------------------ // Allow resizing of rows and columns. grid.setResizeColumns(true); grid.setResizeRows(true); // Allow resizing of row/column headers. grid.setResizeColHeaders(true); grid.setResizeRowHeaders(true); // CONFIGURE SCROLLING ------------------------------------------ // Force the horizontal scroll bar. grid.setHScroll(GridPanel.ALWAYS); // Scroll horizantally by 5 pixels instead of a column at a time. grid.setHScrollAmount(5); // Turn off the vertical scroll bar. grid.setVScroll(GridPanel.NEVER); // CONFIGURE SELECTIONS AND HIGHLIGHTING ----------------------- // Enable selection by rows. grid.setRowSelection(true); // Enable multiple selections. grid.setMultipleSelection(true); // Enable drag selection. grid.setDragSelect(true); // Choose the selection highlighting colors. grid.setHighlightColor(Color.yellow); grid.setHighlightTextColor(Color.red); // CONFIGURE SORTING ------------------------------------------ // Enable sorting for columns 1 and 2 grid.setSortEnable(1, true); grid.setSortEnable(2, true); // Set sort column color to a very light gray. grid.setSortColumnColor(new Color(0xEFEFEF)); // Add the grid into the applet panel add(grid); // Add some data for display. for (int col=1; col<=numCols; col++) { grid.setColHeaderText(col, colLabels[col-1], true); for (int row=1; row<=numRows; row++) { grid.setCellText(col, row, cellData[row-1][col-1], true); } } } }