01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * 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;
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: /**
42: * This method is sent to the renderer by the drawing table
43: * to configure the renderer appropriately before drawing. Return
44: * the Component used for drawing.
45: *
46: * @param table
47: * The JTable that is asking the renderer to draw. This parameter can be null.
48: * @param value
49: * The value of the cell to be rendered. It is up to the specific renderer
50: * to interpret and draw the value. eg. if value is the String 'true',
51: * it could be rendered as a string or it could be rendered as a check box
52: * that is checked. null is a valid value.
53: * @param isSelected
54: * If true the cell is to be renderer with selection highlighting
55: * @param hasFocus
56: * If true the cell has focus.
57: * @param row
58: * The row index of the cell being drawn. When drawing the header the rowIndex is -1.
59: * @param column
60: * The column index of the cell being drawn
61: */
62: public Component getTableCellRendererComponent(JTable table,
63: Object value, boolean isSelected, boolean hasFocus,
64: int row, int column) {
65: Component c = super .getTableCellRendererComponent(table, value,
66: isSelected, hasFocus, row, column);
67:
68: if (c instanceof JLabel) { // add the tool tip
69: JLabel l = (JLabel) c;
70:
71: l.setToolTipText(l.getText());
72: }
73:
74: return c;
75: }
76:
77: }
|