/* 3magic Coffee Table Tutorial 5 Tutorial5.java - Manipulating the selection programmatically. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.applet.*; import java.util.*; import java.awt.event.*; import CoffeeTable.Grid.*; public class Tutorial5 extends Applet implements ActionListener { // Labels for columns. String colLabels[] = {"First", "Last", "Fruit", "Color", "Salary"}; // Sample data. 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"}}; // Our grid. GridPanel fGrid; // Rows and Columns; int fNumRows = 10; int fNumCols = 5; // Some Buttons. int fNumButtons = 7; Button fButton[] = new Button[fNumButtons]; String buttonLabels[] = { "Select All", "Select Row 4", "Select Col 3", "Select Every Other", "Deselect All", "Count Selected Cells", "Visit Selected Cells"}; // A label. Label fLabel; /** * Initialize. */ 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. fGrid = new GridPanel(fNumRows, fNumCols); // Be sure to set the preferred size if you are using it in a // layout that resizes based on preferred size. fGrid.setSize(400, 200); // Show the row headers. fGrid.setRowHeaderWidth(30); fGrid.setRowNumbers(true); // CONFIGURE SELECTIONS AND HIGHLIGHTING ----------------------- // Enable selection by rows. fGrid.setRowSelection(true); // Enable multiple selections. fGrid.setMultipleSelection(true); // Enable drag selection. fGrid.setDragSelect(true); // Choose the selection highlighting colors. fGrid.setHighlightColor(Color.blue); fGrid.setHighlightTextColor(Color.white); // Add the grid into the applet panel add(fGrid); // Add some data for display. for (int col=1; col<=fNumCols; col++) { fGrid.setColHeaderText(col, colLabels[col-1], true); for (int row=1; row<=fNumRows; row++) { fGrid.setCellText(col, row, cellData[row-1][col-1], true); } } // Add some control buttons. for (int i = 0; i