April 9th, 1999, 01:27 PM
I have a JList on a JScrollPane. When my user puts their mouse over each of the items in the list, I want the appropriate item highlighted. The mouse entered event doesn't seem to work, and I don't want this to come off of a click.
Please help!
Anil Kumar
July 9th, 1999, 03:45 PM
The following piece of code should work for you.
listbox.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent me) {
int selectedIndex = listbox.locationToIndex(me.getPoint());
if (selectedIndex < 0)
return;
listbox.setSelectedIndex(selectedIndex);
listbox.repaint();
}
});