Java JTable Create from TableModel constructTable(TableModel model)

Here you can find the source of constructTable(TableModel model)

Description

This method returns a table with the given model.

License

Open Source License

Declaration

public static JTable constructTable(TableModel model) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

import javax.swing.JTable;

import javax.swing.table.TableModel;

public class Main {
    /**This method returns a table with the given model.
     * The table will be not editable and only row selection will be allowed. */
    public static JTable constructTable(TableModel model) {

        JTable table = new JTable() {

            private static final long serialVersionUID = -5079355133615100914L;

            @Override//from   w w  w . j a  v a  2  s .c  o  m
            public boolean isCellEditable(int x, int y) {
                return false;
            }
        };

        table.setModel(model);
        table.setColumnSelectionAllowed(false);
        table.setRowSelectionAllowed(true);
        table.setSelectionForeground(Color.BLUE);
        return table;
    }
}