Java tutorial
import java.awt.Dimension; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; public class Main { public static void main(String[] args) throws Exception { String[] columns = { "Name", "Age" }; Object[][] content = { { "R", new Integer(24) }, { "A", new Integer(25) }, { "J", new Integer(30) }, { "A", new Integer(32) }, { "S", new Integer(27) } }; JTable table = new JTable(content, columns); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jPanel = new JPanel(new GridLayout(2, 0)); jPanel.setOpaque(true); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); jPanel.add(new JScrollPane(table)); /* Add the panel to the JFrame */ frame.add(jPanel); /* Display the JFrame window */ frame.pack(); frame.setVisible(true); table.print(); } }