/* 3magic Coffee Table Tutorial 12 Tutorial12.java - Multiline Text. © 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 Tutorial12 extends Applet implements ActionListener { // Labels for columns. String colLabels[] = {"1st Quarter\n1996", "2nd Quarter\n1996", "3rd Quarter\n1996", "4th Quarter\n1996", "1st Quarter\n1997", "2nd Quarter\n1997", "3rd Quarter\n1997", "4th Quarter\n1997"}; // Labels for rows. String rowLabels[] = {"Asia", "North America", "South America", "Europe"}; // Sample data. String cellData[][] = { {"Japan: $4K\nChina: $5K\nMalaysia: $10K", "Japan: $7K\nChina: $3K\nMalaysia: $8K", "Japan: $8K\nChina: $5K\nMalaysia: $10K", "Japan: $14K\nChina: $6K\nMalaysia: $13K", "Japan: $13K\nChina: $15K\nMalaysia: $14K", "Japan: $22K\nChina: $15K\nMalaysia: $20K", "Japan: $28K\nChina: $35K\nMalaysia: $30K", "Japan: $39K\nChina: $35K\nMalaysia: $45K"}, {"USA: $4K\nCanada: $5K\nMexico: $13K", "USA: $4K\nCanada: $15K\nMexico: $10K", "USA: $21K\nCanada: $35K\nMexico: $18K", "USA: $33K\nCanada: $15K\nMexico: $15K", "USA: $15K\nCanada: $14K\nMexico: $22K", "USA: $25K\nCanada: $23K\nMexico: $23K", "USA: $33K\nCanada: $18K\nMexico: $13K", "USA: $55K\nCanada: $21K\nMexico: $30K"}, {"Brazil: $13K\nArgentina: $15K\nChile\nPeru: $10K", "Brazil: $4K\nArgentina: $5K\nChile\nPeru: $12K", "Brazil: $14K\nArgentina: $25K\nChile\nPeru: $10K", "Brazil: $44K\nArgentina: $53K\nChile\nPeru: $13K", "Brazil: $45K\nArgentina: $15K\nChile\nPeru: $18K", "Brazil: $64K\nArgentina: $35K\nChile\nPeru: $30K", "Brazil: $22K\nArgentina: $32K\nChile\nPeru: $50K", "Brazil: $14K\nArgentina: $12K\nChile\nPeru: $15K"}, {"France: $24K\nEngland: $5K\nGermany: $10K\nItaly: $11K\nSpain: $120K", "France: $34K\nEngland: $52K\nGermany: $13K\nItaly: $14K\nSpain: $120K", "France: $42K\nEngland: $132K\nGermany: $11K\nItaly: $122K\nSpain: $20K", "France: $11K\nEngland: $22K\nGermany: $15K\nItaly: $152K\nSpain: $40K", "France: $23K\nEngland: $42K\nGermany: $13K\nItaly: $12K\nSpain: $25K", "France: $13K\nEngland: $222K\nGermany: $120K\nItaly: $88K\nSpain: $76K", "France: $22K\nEngland: $12K\nGermany: $120K\nItaly: $59K\nSpain: $43K", "France: $56K\nEngland: $5K\nGermany: $145K\nItaly: $123K\nSpain: $222K"}, }; // Our grid. GridPanel fGrid; // Rows and Columns; int fNumRows = 4; int fNumCols = 8; // Some Buttons. int fNumButtons = 2; Button fButton[] = new Button[fNumButtons]; String buttonLabels[] = { "Clear Data", "Reload Data"}; /** * 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); // Set up the row/col dimensions. fGrid.setRowHeight(65); fGrid.setColHeaderHeight(40); fGrid.setRowHeaderWidth(80); // Let's use Times, plain, 9-point. fGrid.setGridFont(new Font("TimesRoman", Font.PLAIN, 9)); // Set the background color. fGrid.setGridBackground(new Color(230, 255, 230)); // light green. fGrid.setHeaderBackground(new Color(230, 230, 255)); // light blue. // CONFIGURE WORD_WRAP ------------------------------------------ // Multiline text. GridAttributes ga = fGrid.getGridAttributes(); ga.setJustification(ga.getJustification() | GridPanel.WORD_WRAP); // Multiline column headers. ga = fGrid.getColHeaderAttributes(0); ga.setJustification(GridPanel.JUST_CENTER | GridPanel.WORD_WRAP); // Add some data for display. this.loadData(); // Add the grid into the applet panel add(fGrid); // Add some control buttons. for (int i = 0; i