Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

set ToolTip to each item of JList?

  Asked By: Everett    Date: Apr 04    Category: Java    Views: 2739
  

I want set Tooltip to each item of JList

and i had taken array of list and JList is

createing using DefaultListModel

How i can set the tooltip to each item of

the JList

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Saxon Anderson     Answered On: Apr 04

I can help you with javascript code for it :


if (!document.layers&&!document.all&&!document.getElementById)
event="test";
function showtip(current,e,text) {

if (document.all||document.getElementById) {
thetitle=text.split('<br>');
if (thetitle.length>1) {
thetitles='';
for (i=0;i<thetitle.length;i++)
thetitles+=thetitle[i];
current.title=thetitles;
}
else
current.title=text;
}

else if (document.layers) {
document.tooltip.document.write('<layer bgColor="yellow" style="border:1px;font-size:18px;font-family: nazli;font-color: #0f1c5e;">'+text+'</layer>');
document.tooltip.document.close();
document.tooltip.left=e.pageX+5;
document.tooltip.top=e.pageY+5;
document.tooltip.visibility="show";

}
}
function hidetip(){
if (document.layers)
document.tooltip.visibility="hidden";
}

and it's use is :

<a href="#" onmouseout="hidetip();" onmouseover="showtip(this,event,'text to show');">Sample</a>

you could use it in your iterator for JList.

 
Answer #2    Answered By: Geraldine Perkins     Answered On: Apr 04

Consider overriding getToolTipText( MouseEvent event) method in your JList class. You may need to add the support yourself.

 
Answer #3    Answered By: Corey Jones     Answered On: Apr 04

/* only must track item  of mouse-over.then use locationToIndex(Point) for
turn point to item of list  , then you list.setToolTipText(relatedValue)*/


private class MyJList extends JList {

int itemIndexUnderMouse;

public MyJList(Object[] values) {
super(values);
itemIndexUnderMouse = -1;
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point point = indexToLocation(0);
int index = locationToIndex(e.getPoint());
if (index != itemIndexUnderMouse ||
itemIndexUnderMouse == -1) {
updateToolTip(index);
}
}
});
}

private void updateToolTip(int index) {
String newToolTip = (String) (getModel().getElementAt(index));
// or each thing that you want
setToolTipText(newToolTip);
}
}

 
Didn't find what you were looking for? Find more on set ToolTip to each item of JList? Or get search suggestion and latest updates.




Tagged: