Hi Klein. Im assuming you mean that some of the cells text in the List is hidden, and not the complete cell, otherwise ToolTip text won't show anyway.
To determine whether the text is partially hidden, i.e., partially off the screen, you'll need the width of the list, the starting location of the text, and the width of the text. Im going to let you worry about getting the first 2.
To get the pixel length of the text in the cell, you'll need to use a
object. Creating these can be a pain, but they're the only accurate way to measure the pixel length of Strings. I usually wait till I get into the paint method before creating them, because it's easier to get them from a graphics object. Anyone who knows a better way to make one, let me know. This is what I usually do.
Code:
FontMetrics fontMetrics;
public void paint (Graphics graphics) {
if (fontMetrics == null) {
fontMetrics = grpahics.getFontMetrics ();
}
}
Once you actually have the
object, you can get the length of you text in your cells.
There are a lot different ways to pass in your text, all require a Graphics object, though. I usually use
Code:
getStringBounds (String, Graphics)
which retursn a
object, from which you can get the width of the text.
Finally, take the starting location of the text, add to it the width of the text, and compare that against the width of the cell. If
Code:
start + textWidth > cellWidth
, then the text is partially hidden.
However, if all you want is to have the ToolTip display the full text, I would set the ToolTip for all cells to be its text, then you won't have to worry about doing all this checking, though it doesn't hurt knowing how to do it.
Hope this helps,
MarsChelios