Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Everett James   on Apr 04 In Java Category.

  
Question Answered By: Corey Jones   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);
}
}

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
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: