setup JTable - Java Swing

Java examples for Swing:JTable

Description

setup JTable

Demo Code


//package com.java2s;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

public class Main {
    @SuppressWarnings("serial")
    public static void setupTable(JTable jTable,
            TableCellRenderer tableCellRenderer, String[][] content) {

        jTable.setModel(new DefaultTableModel(content, content[0]) {
            @Override/*from  w  w  w .  jav a 2 s.c  om*/
            public boolean isCellEditable(int i, int j) {
                return false;
            }
        });

        for (int j = 0; j < jTable.getColumnModel().getColumnCount(); j++) {
            jTable.getColumnModel().getColumn(j)
                    .setCellRenderer(tableCellRenderer);
        }
        jTable.doLayout();
    }
}

Related Tutorials