devdaily home | java | perl | unix | directory | blog

What this is

This file is part of the Tame Swing collection that we have compiled. All of the Java source code in these examples was created by Nobuo Tamemasa. As these examples have become hard to find on the internet, we have put them in one place here, supported by minimal advertising. In time we will include images of each running sample Java/Swing application.

The intent of having these files here is to help you learn Java and Swing by example, and Tame certainly created some terrific examples of the power of the Swing framework.

Other links


java, swing, example, sample, source, custom, table, jtable, cell, header, model, row, column

The source code

package tame.examples;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

import tame.table.ColumnGroup;
import tame.table.GroupableTableHeader;

 *  (swing1.1beta3)
 * |-----------------------------------------------------|
 * |   1st  |      2nd        |          3rd             |
 * |-----------------------------------------------------|
 * |        |        |        |        |        |        |
@author Nobuo Tamemasa
@version 1.0 11/09/98
public class MultiWidthHeaderExample extends JFrame {

  MultiWidthHeaderExample() {
    super( "Multi-Width Header Example" );

    DefaultTableModel dm = new DefaultTableModel();
    dm.setDataVector(new Object[][]{
    new Object[]{"1 st","","","","",""});

    JTable table = new JTable( dm ) {
      protected JTableHeader createDefaultTableHeader() {
	return new GroupableTableHeader(columnModel);
    TableColumnModel cm = table.getColumnModel();
    ColumnGroup g_2nd = new ColumnGroup("2 nd");
    ColumnGroup g_3rd = new ColumnGroup("3 rd");
    GroupableTableHeader header = (GroupableTableHeader)table.getTableHeader();
    JScrollPane scroll = new JScrollPane( table );
    getContentPane().add( scroll );
    setSize( 400, 100 );

  public static void main(String[] args) {
    MultiWidthHeaderExample frame = new MultiWidthHeaderExample();
    frame.addWindowListener( new WindowAdapter() {
      public void windowClosing( WindowEvent e ) {

Copyright 1998-2009
All Rights Reserved.