/* * TableToGridDemo.java * * Copyright 2000 Eliad Technologies, Inc. All Rights Reserved. * * This software is the proprietary information of Eliad Technologies, Inc. */ package example04; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import com.eliad.swing.*; import com.eliad.util.*; /** * This demo shows how to display a table model inside a JSmartGrid. * @author Daniel Rosenblatt * @version 1.0 */ public class TableToGridDemo extends JFrame { JSmartGrid grid_; /** Creates a new SimpleGrid */ public TableToGridDemo() { super("Simple Table to Grid Example"); addWindowListener ( new WindowAdapter () { public void windowClosing(WindowEvent evt) { System.exit(0); } } ); TableModel tableModel = new DefaultTableModel(10,10); for (int row = 0; row < 10; row++) { for (int col = 0; col < 9; col++) if ((col%2)==(row%2)) tableModel.setValueAt("" + row + col, row, col); else tableModel.setValueAt(new Integer(row*10 + col), row, col); tableModel.setValueAt(new Boolean((row%2)==0), row, 9); } TableColumnModel tableColumnModel = new DefaultTableColumnModel(); for (int col = 0; col < 10; col++) { TableColumn tc = new TableColumn(col); String num; switch (col) { case 0: num="st";break; case 1: num="nd";break; case 2: num="rd";break; default: num="th";break; } tc.setHeaderValue((col+1)+num); tableColumnModel.addColumn(tc); } TableToGridMapper tableToGridMapper = new TableToGridMapper(tableModel); tableToGridMapper.setTableColumnModel(tableColumnModel); grid_ = new JSmartGrid(tableToGridMapper); for (int col = 0; col < grid_.getColumnCount(); col++) grid_.setColumnWidth(col, 50); JScrollPane js = new JScrollPane(grid_); grid_.setColumnHeader(new JSmartGridHeader(grid_,grid_.HORIZONTAL,tableToGridMapper.getColumnHeaderModel(),null,null)); getContentPane().add(js, BorderLayout.CENTER); pack(); } /** Creates and displays a SimpleGrid frame */ public static void main(String[] args) { TableToGridDemo sg = new TableToGridDemo(); Dimension big=Toolkit.getDefaultToolkit().getScreenSize(); Dimension small=sg.getSize(); sg.setLocation((big.width-small.width)/2, (big.height-small.height)/2); sg.setVisible(true); } }