// File: JTableDemo.java 
// Uses DataModel.java
//      create.sql (to create the MySQL database)
//
// Assumes that a MySQL database (documents) exists containing a user_list table
// The user_list table contains 4 columns: name, address, state, zip
//

/*
    This is an example on how to load/populate data from a database 
    (e.g mySQL, Oracle, Sybase) or other repository to a swing JTable.
    JTable is simply a view of the data.
    You may notice that we implemented AbstractTableModel to populate
    the data into the JTable.
*/

/** http://www.javaadvice.com/javaadvice/servlet/ja/action?cmd=ja.advices.rss&type=awtswing&qNo=1 */

import java.awt.Dimension;
import javax.swing.*;

public class JTableDemo extends JPanel {

    public JTableDemo() {
        JTable table = new JTable( new DataModel() );
        table.setPreferredScrollableViewportSize(new Dimension(500, 300));
        // Create a scroll pane and attach the table
        JScrollPane sPane = new JScrollPane(table);
        add(sPane);
    }

    /*
     * Create the GUI
     */
    private static void loadGUI() {
        JFrame frame = new JFrame("JTableDemo from JavaAdvice.com");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTableDemo newContentPane = new JTableDemo();
        frame.setContentPane(newContentPane);
        frame.pack();
        frame.setLocation(200, 100);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        loadGUI();
    }

}
