Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about JTable and tooltips  RSS feed

 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using java 1.5.0_07 on Windows 2000 Service Pack 4.
I hava a GUI application that uses JTable.
I have added tooltips to the JTable cells by extending class "javax.swing.table.DefaultCellRenderer" and overriding its "getTableCellRendererComponent" method.
My implementation includes the following:

The table cell renderer component derives from JLabel.
If the JLabel text does not fit into its bounds, its displayed text is truncated and an ellipsis added, for example:

This text is too lon...

How can I get the tooltip to appear only for those cells where the text is truncated?

Also, how can I control the amount of time to wait before displaying the tooltip?

Thanks,
Avi.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Avi Abrami:

How can I get the tooltip to appear only for those cells where the text is truncated?

Also, how can I control the amount of time to wait before displaying the tooltip?


Check out this link.



Also, how can I control the amount of time to wait before displaying the tooltip?


ToolTipManager is your friend for this one.
Typically you obtain a reference by calling ToolTipManager#sharedInstance.
Then you register your component whose tool tip interval you want to tweak by using ToolTipManager#registerComponent(JComponent component). Then you can use the ToolTipManager#setInitialDelay(int initialDelay) to specify the time interval you want.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maneesh.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
Seems to me that all JComponents are managed by the same, single instance of class javax.swing.ToolTipManager.
Hence changing "initial delay" for one component changes it for all components.
Please verify whether I am correct.
If I am correct then is there a way to change the initial delay for one component only while leaving initial delay for other components unchanged?

Thanks,
Avi.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Avi Abrami:

If I am correct then is there a way to change the initial delay for one component only while leaving initial delay for other components unchanged?


In that case I would suggest the following approach.
1)Add a mouse listener to your component.
2)On mouseEntered you start a timer.
3)After the required time interval, you programatically show the tooltip.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!