Java JTable Create createTable(final String[] pHeaderToolTips)

Here you can find the source of createTable(final String[] pHeaderToolTips)

Description

create Table

License

Open Source License

Declaration

public static JTable createTable(final String[] pHeaderToolTips) 

Method Source Code


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

import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;

public class Main {
    public static JTable createTable(AbstractTableModel pTableModel, final String[] pHeaderToolTips) {
        JTable tTable = new JTable(pTableModel) {
            private static final long serialVersionUID = 0L;

            protected JTableHeader createDefaultTableHeader() {
                return new JTableHeader(columnModel) {
                    private static final long serialVersionUID = 0L;

                    public String getToolTipText(MouseEvent e) {
                        java.awt.Point p = e.getPoint();
                        int index = columnModel.getColumnIndexAtX(p.x);
                        int realIndex = columnModel.getColumn(index).getModelIndex();
                        return pHeaderToolTips[realIndex];
                    }/*from w  w w .  j a  va2 s  . c  om*/
                };
            }
        };
        return tTable;
    }

    public static JTable createTable(final String[] pHeaderToolTips) {
        JTable tTable = new JTable() {
            private static final long serialVersionUID = 0L;

            protected JTableHeader createDefaultTableHeader() {
                return new JTableHeader(columnModel) {
                    private static final long serialVersionUID = 0L;

                    public String getToolTipText(MouseEvent e) {
                        java.awt.Point p = e.getPoint();
                        int index = columnModel.getColumnIndexAtX(p.x);
                        int realIndex = columnModel.getColumn(index).getModelIndex();
                        return pHeaderToolTips[realIndex];
                    }
                };
            }
        };
        return tTable;
    }
}

Related

  1. createTable()
  2. createTable(Component... comps)