Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

tooltips in JTable cells

Thread view: 
Ike - 01 Dec 2003 20:27 GMT
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
Amit Brabbing - 01 Dec 2003 21:01 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.