I have a JTable that I would like to display a fancy tooltip (basically a JTextArea) for particular cells in a column. I am using a custom cell renderer, so it would be easy if I could figure out how to popup a window when I hover over the cell renderer's component.
Are there any examples of how to do this?
I'm not sure I totally am clear on what sort of customizations specifically you're hoping to do, so I'll be general here.
There is a class, UIManager, that controls the look and feel of components, including the swing ToolTip class. The simple way to make an easy change is to call a method in UIManager to set properties for the tooltips. Doing this you could do things like use BorderFactory to add a decorative border, or change the background color, etc.
Here are some examples of changing some of these properties:
If you want to change a whole bunch of things about their look and feel, it is better to extend your current look and feel with a class implementing custom tooltip look and feel. A full example of this can be found in this blog post by a former Sun developer.
You might also have a look at this Stack Overflow question on how to set the insets on a tooltip.
You can use HTML in tooltips, if you use the
<html>
and</html>
tags around the content.Use HTML to format the tooltip. Using colored (
<font>
) and multi-line (<br>
) tooltips is now easy.Creating and overwriting the default
JToolTip
is a bit harder. Every component has aJToolTip
instance and you can retrieve this one withJComponent.createToolTip()
. To create a custom tooltip, extend the cell renderer and override it'screateToolTip
to implement your custom functionality (return a custom extended version ofJToolTip
).