You can use your own cell renderer and then set the cell renderer tooltip
with the value of the cell.
something like this:
package Learn;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.JTable;
import java.awt.Component;
public class MyRenderer extends DefaultTableCellRenderer
{
public MyRenderer()
{
}
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
return this.setToolTipText(value.toString());
}
}
and then you can set it as your own cell render in each column.
Hope it helps you
Amit Brabbing
> How can I set tooltips such that when the mouse is over a given cell, the
> value of that cell shows (assuming the cell is String), useful for very
> narrow columns?
>
> Thanks, Ike
Ike - 01 Dec 2003 21:41 GMT
But...I already have a cell renderer on them;
> You can use your own cell renderer and then set the cell renderer tooltip
> with the value of the cell.
[quoted text clipped - 34 lines]
> >
> > Thanks, Ike
Ike - 01 Dec 2003 22:02 GMT
http://www.codeguru.com/java/articles/123.shtml
SPC - 03 Dec 2003 10:16 GMT
> http://www.codeguru.com/java/articles/123.shtml
I had some code similar to this and it *also* calculated the fit of
the data in the cell and returned a tooltip only if the value didn't
fit. It worked well enough until people wanted to put html into their
data values. At that point the performance was awful when the mouse
was moved down a column because rendering html is a CPU intensive
business and value had to be 'rendered' to get its size. Add this to
the fact that the tooltip is fetched for each mouse point moved and
you can see where the cpu went.
So, I wrote more code to record the current cell and only do the size
check once on the first entry into the cell, recording the tip
location and tip as well.
HTH
Steve