FileDocCategorySizeDatePackage
RowHeaderTable.javaAPI DocExample3524Thu Oct 24 20:14:26 BST 2002None

RowHeaderTable.java

// RowHeaderTable.java
// A simple application that demonstrates the use of the TableColumnModel
// class to build a row header column that scrolls with the regular data
// rows.
//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class RowHeaderTable extends JFrame {

  public RowHeaderTable() {
    super("Row Header Test");
    setSize(300, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    

    TableModel tm = new AbstractTableModel() {
      String data[] = {"", "a", "b", "c", "d", "e"};
      String headers[] = {"Row #", "Column 1", "Column 2", "Column 3", 
                          "Column 4", "Column 5"};
      public int getColumnCount() { return data.length; }
      public int getRowCount() { return 1000; }
      public String getColumnName(int col) { return headers[col]; }
      
      // Synthesize some entries using the data values & the row #
      public Object getValueAt(int row, int col) { 
        return data[col] + row; 
      }
    };

    // Create a column model for the main table. This model ignores the first
    // column added, and sets a minimum width of 150 pixels for all others.
    TableColumnModel cm = new DefaultTableColumnModel() {
      boolean first = true;
      public void addColumn(TableColumn tc) {
        // Drop the first column . . . thatâ