import java.util.*; 
import java.awt.*; 
import javax.swing.*; 
import javax.swing.table.*; 
import com.lavantech.gui.comp.*;
 
public class TestTableDateTimePicker extends JPanel
{
    public TestTableDateTimePicker()
    {
        String formatString = "dd-MMM-yy HH:mm";
        setLayout(new BorderLayout());

        JTable table = new JTable(new TestTableModel());
        table.setDefaultEditor(Date.class, new DateTimeCellEditor(formatString));
        table.setDefaultRenderer(Date.class, new DateTimeCellRenderer(formatString));
        table.setPreferredScrollableViewportSize(new Dimension(250,150));
        add(new JScrollPane(table), BorderLayout.CENTER);
        add(new JLabel("Click on the Date Cell to Edit"), BorderLayout.SOUTH);
    }

    class TestTableModel extends AbstractTableModel
    {
        String[] colNames = {"Game Schedule", "Date" };
        String[] events = {"Team A vs Team B", "TeamB vs Team C",
            "Team C vs Team A", "Team D vs Team A", "Team D vs Team B",
            "Team D vs Team C"};

        Date[] dates = new Date[6];

        public TestTableModel()
        {
        }

        public int getRowCount()
        {
            return events.length;
        }

        public int getColumnCount()
        {
            return 2;
        }

        public String getColumnName(int c)
        {
            return colNames[c];
        }

        public Object getValueAt(int r, int c)
        {
            if(c == 0)
                return events[r];
            else
                return dates[r];
        }

        public Class getColumnClass(int c)
        {
            if(c == 0)
                return String.class;
            else    
                return Date.class;
        }

        public void setValueAt(Object obj, int r, int c)
        {
            if(c == 1)
            {
                dates[r] = (Date)obj;
                fireTableCellUpdated(r,c);
				if(dates[r] != null)
                	System.out.println(events[r]+ " " + dates[r]);
				else
                	System.out.println(events[r]+ " not scheduled");
            }
        }

        public boolean isCellEditable(int r, int c)
        {
            if(c == 1)
                return true;
            else 
                return false;
        }
    }

}
