aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes tooltiptext question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "tooltiptext question" Watch "tooltiptext question" New topic
Author

tooltiptext question

Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Hi,
I am rendering a panel in a JTable cell.This panel contains two components-a JLabel & a JButton.I want to display a tooltiptext for this button.In my renderer I say:
btn.setToolTipText("Display ToolTip");
But it does not work.
When I set the tooltiptext for the panel then it works fine and I can see the tooltiptext for that cell in my JTable.But I just want the tooltip to show up when the mouse is somewhere on the button not on the label.
Any suggestions??What am I doing wrong here??
Thx
Pomchi
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
I wonder, since you add the btn onto the panel, you should call btn.setToolTipText("...") in the implementation code of the panel, instead of the renderer.


" Veni, vidi, vici "<br />" I came, I saw, I conquered "
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
I think it depends on what you want to show in the tooltip, Pomchi.
If its a constant value then you can set the value in the button code's implementation, but if you are ,say , trying to display the particular cell value or something, then you have to get the value first & then display in the tooltip.


- Vinod<br />-------<br />SCJP2
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Hi Vinod,
I am trying to display a constant value as the tooltiptext.
I know this is quite weird but setToolTipText("Display text") does not work for label or button that are components of the panel.....but works for the panel.
Please suggest any solution.I just want the tooltiptext for the button.
Thanks
Pomchi
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Hi Laudney,
This is what I am doing.In my renderer I am creating a label, a button and a panel.After adding the label and the button to the panel I am returning the panel from getTableCellRendererComponent(....)
This is where I am calling btn.setToolTipText("Display Text");
Neither this nor label.setToolTipText("Display") works.Only panel.setToolTipText("gjhgh") works fine.
Any suggestions
Thanks
Pomchi
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Thats the problem, Pomchi, your getTableCellRendererComponent returns a component & in your case its a panel, so thats y the panel gets the tooltip text.
Now you can't assign the tooltip in the renderer method, what you can do is outside the renderer code, assign explicitly to each button the tooltip. Now I know this is cumbersome but if you could post your code maybe I can get some more ideas.
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Vinod,
Thanks for your prompt reply!
I am a little confused here.From the same place( inside the renderer) I can change the margin of the button using setMargin.I can set the background of the label or the button.It lets me do all these things but why not tooltiptext??
In my code I am checking for some values in other cells of the same row and depending upon the values I want to render a panel (containing a label & a button) or just a Label.Where else can I create this button if not renderer??(I tried passing the button to the constructor of the renderer.This won't work either.)
I can post the code but this button just comes up in my renderer.Please let me know if you want to see my renderer code.I'll post that.
-Pomchi
Laudney Ren
Ranch Hand

Joined: Jan 06, 2002
Posts: 111
Please post the renderer code.
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
mail me the entire code.
Pomchi Bedi
Ranch Hand

Joined: Apr 03, 2001
Posts: 55
Here is my code:

Thanks
Pomchi
[ January 10, 2002: Message edited by: Pomchi Bedi ]
Nathan Pruett - I edited the really long line in the code to wrap...
[ January 11, 2002: Message edited by: Nathan Pruett ]
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
I wanted to see the whole code..but anyways, what u could do is based on cell value call a method which returns the appropriate component..but still ur final component returned is Panel.
So the only other way is to create a separate editor class for your table, like for example ,LabelEditor which extends DefaultCellEditor..or for that matter ButtonEditor...& in this class you can set the properties like tooltip.
Vinod
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tooltiptext question
 
Similar Threads
Swing/ToolTipText
ToolTipText
ToolTipText
Hover Text Vs ToolTipText
ToolTipText