package CITableTest;

import java.awt.Color;

* @author  Somchai LIMSIRORATANA, Nuntiya LIMSIRORATANA(Yawai)
* @version 1.1
* @author Weerasak WITTAWASKUL
* 1MAY2003 Move setDefaultCellEditorRenderer to
*          Add toggleModel to support model switch between data1 and data2
public class TestCITable extends javax.swing.JFrame {
    private boolean toggleModel = true;
    Object[][] data1 = {{"ID", new Integer(1234)},
                       {"Name", "Somchai"},
                       {"Family Name", "LIMSIRORATANA"},
                       {"Weight", new Float(62.8)},
                       {"Single", new Boolean(false)},
                       {"Hair Color", new Color(20, 0, 0)},
                       {"File", new FileName("C:\\TEMP\\Test.txt")}
    String[] colname1 = {"Properties","Value"};

    Object[][] data2 = {{"Student1", new Integer(12), new Float(1.45), new Color(0,0,0)},
                        {"Student2", new Long(4567890), new Color(0,0,0), new Boolean(true)},
                        {"Student3", new Double(123456), new FileName("C:\\TEMP\\Test1.dat"), new Integer(0)},
                        {"Student4", new Float(24.56), "Nothing" , new Boolean(false)}
    String[] colname2 = {"Name","Any", "Any", "Any"};

    CellIndependentTable table;
    /** Creates new form TestProperties */
    public TestCITable() {
        table = new CellIndependentTable(new CellIndependentTableModel(data1,colname1));

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    private void initComponents() {//GEN-BEGIN:initComponents
        jScrollPane1 = new javax.swing.JScrollPane();
        jButton1 = new javax.swing.JButton();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton1.setText("Change Data");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {

        getContentPane().add(jButton1, java.awt.BorderLayout.NORTH);


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (toggleModel)
            table.setModel(new CellIndependentTableModel(data2,colname2));
            table.setModel(new CellIndependentTableModel(data1,colname1));
        toggleModel = !toggleModel;

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        javax.swing.table.TableModel model = table.getModel();
        int nrow = model.getRowCount();
        int ncol = model.getColumnCount();
        for (int r=0; r<nrow; r++) {
            for (int c=0; c<ncol; c++) {
                Object value = model.getValueAt(r,c);

    * @param args the command line arguments
    public static void main(String args[]) {
        new TestCITable().show();

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables