// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;

public class Table2 extends JFrame {
    public Table2() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setLayout(new BorderLayout());
        setTitle("Simple table");
        JTable tbl = new JTable(new MyModel());
        getContentPane().add(new JScrollPane(tbl), BorderLayout.CENTER);
        pack();
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new Table2();
                f.setVisible(true);
            }
        });
    }
}

class MyModel extends AbstractTableModel {
    private String[] colnam = new String[] { "F1", "F2" };
    private Object[][] data = new Object[][] { new Object[] { 1, "A" },new Object[] { 2, "BB" },new Object[] { 3, "CCC" } }; 
    @Override
    public int getColumnCount() {
        return 2;
    }
    @Override
    public int getRowCount() {
        return 3;
    }
    public String getColumnName(int colix) {
        return colnam[colix];
    }
    @Override
    public Object getValueAt(int rowix, int colix) {
        return data[rowix][colix];
    }
}
