# JTableSimpleExample.java Simple table that takes column names and data from arrays of Strings. import java.awt.*; import javax.swing.*; /** Simple JTable example that uses a String array for the * table header and table data. * */ public class JTableSimpleExample extends JFrame { public static void main(String[] args) { new JTableSimpleExample(); } private final int COLUMNS = 4; private final int ROWS = 15; private JTable sampleJTable; public JTableSimpleExample() { super("Creating a Simple JTable"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); String[] columnNames = buildColumnNames(COLUMNS); String[][] tableCells = buildTableCells(ROWS, COLUMNS); sampleJTable = new JTable(tableCells, columnNames); JScrollPane tablePane = new JScrollPane(sampleJTable); content.add(tablePane, BorderLayout.CENTER); setSize(450,150); setVisible(true); } private String[] buildColumnNames(int columns) { String[] header = new String[columns]; for(int i=0; i
JTable Examples
Permanent link to this article: http://bangla.sitestree.com/jtable-examples/