KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > swing > CellRendererWithToolTip


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22
23 package org.enhydra.kelp.common.swing;
24
25 import java.awt.Component JavaDoc;
26 import javax.swing.*;
27 import javax.swing.table.*;
28
29 /**
30  * Override the default TableCellRenderer so that we can set the tool tip
31  * for each cell. The tool tip is handy for long path names.
32  */

33 public class CellRendererWithToolTip extends DefaultTableCellRenderer {
34
35     /**
36      * Create a CellRendererToolip.
37      */

38     public CellRendererWithToolTip() {}
39
40     /**
41      * This method is sent to the renderer by the drawing table
42      * to configure the renderer appropriately before drawing. Return
43      * the Component used for drawing.
44      *
45      * @param table
46      * The JTable that is asking the renderer to draw. This parameter can be null.
47      * @param value
48      * The value of the cell to be rendered. It is up to the specific renderer
49      * to interpret and draw the value. eg. if value is the String 'true',
50      * it could be rendered as a string or it could be rendered as a check box
51      * that is checked. null is a valid value.
52      * @param isSelected
53      * If true the cell is to be renderer with selection highlighting
54      * @param hasFocus
55      * If true the cell has focus.
56      * @param row
57      * The row index of the cell being drawn. When drawing the header the rowIndex is -1.
58      * @param column
59      * The column index of the cell being drawn
60      */

61     public Component JavaDoc getTableCellRendererComponent(JTable table,
62         Object JavaDoc value, boolean isSelected, boolean hasFocus, int row,
63         int column) {
64     Component JavaDoc c = super.getTableCellRendererComponent(table, value,
65         isSelected, hasFocus, row, column);
66
67     if (c instanceof JLabel) { // add the tool tip
68
JLabel l = (JLabel) c;
69
70         l.setToolTipText(l.getText());
71     }
72
73     return c;
74     }
75
76 }
77
Popular Tags