• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with tool tips (which do not contain plane text) in JList  RSS feed

 
Petar Lukovic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi...

I have problem with tool tips in JList. I would like to make my application show different tool tip for everu cell in JList. But, nither cells in Jlist, nither tool tips contain plain text. Cells in Jlist have a cell renderer which is a actually a JPanel that overrides paintComponent() method (SmallMessagePanel in the folowing code). Tool tips also contain JPanel that overrides paintComponent() method (BigMessageToolTip, containig refernce to BigMessagePanel, in the folowing code).

Now, I succseded to get tool tips like these, when JList is not involved. When I just SmallMessagePanel it displays BigMessageToolTip with no proble, just as I want it to. But when SmallMessagePanel is placed in a JList as a cell, BigMessageToolTip doesn't work. Tool tips shows, but is has a plain text, and it is the same for every cell in the list.

Here is code:









and a cell renderer:



I have of course a line that sets cell renderer to a JList in my code.



Does enyone knows how to solove this problem?
Thank you very much ...




 
Petar Lukovic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I found solution...

I overrided the JList class with a new called JList withToolTips, which has a MouseMotionListener,



and used it instead. And it works...
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the documentation for getToolTipText(MouseEvent)? It says two things:
1) register your JList.
2) call setToolTipText on the cell renderer component upon showing it.

You would of course need to create a custom cell renderer. The simple way would be to extend DefaultListCellRenderer:
You just base the tool tip text for the renderer component on the value, which should be an MessageData instance.
 
Petar Lukovic
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you Rob ...

That is much more elegant solution.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!