import javax.swing.*; class TestCase { public static void main(String args[]) { JFrame jf = new JFrame(); JPanel topPanel; JTable table; JScrollPane scrollPane; // Create a panel to hold all other components topPanel = new JPanel(); jf.getContentPane().add( topPanel ); // Create columns names String columnNames[] = { "Column 1", "Column 2", "Column 3" }; // Create some data String dataValues[][] = { { "12", "234", "67" }, { "-123", "43", "853" }, { "93", "89.2", "109" }, { "279", "9033", "3092" } }; // Create a new table instance table = new JTable( dataValues, columnNames ); table.setColumnSelectionAllowed(true); table.setRowSelectionAllowed(true); // Add the table to a scrolling pane scrollPane = new JScrollPane( table ); topPanel.add( scrollPane); jf.pack(); jf.show(); } }