Saturday, January 25, 2014

jTable Row Value Tool Tip

jTable_direct_delivery = new javax.swing.JTable()
{

    //JTable

    //Implement table cell tool tips.        
    public String getToolTipText(MouseEvent e) {
        String tip = null;
        java.awt.Point p = e.getPoint();
        int rowIndex = rowAtPoint(p);
        int colIndex = columnAtPoint(p);
        int realColumnIndex = convertColumnIndexToModel(colIndex);

        try {
            // if (realColumnIndex == 2 && rowIndex!=0) { //comment row, exclude heading
                //     tip = getValueAt(rowIndex, colIndex).toString();
                // }
            if (realColumnIndex == 9 ) { //comment row, exclude heading
                tip = "Dispatch";
            }
            if (realColumnIndex == 10 ) { //comment row, exclude heading
                tip = "Edit";
            }

            if (realColumnIndex == 2 && rowIndex >=0 ) { //comment row, exclude heading
                tip = getValueAt(rowIndex, colIndex).toString();
            }
        } catch (RuntimeException e1) {
            //catch null pointer exception if mouse is over an empty line
        }

        return tip;
    }

}
;

No comments:

Post a Comment