JList中,当鼠标移动到某一项上时就高亮显示,该怎么做这个事件?
------解决方案--------------------
- Java code
Point lastPoint;jlist.addMouseListener(new MouseAdapter(){ @Override public void mouseEntered(MouseEvent e){ lastPoint = e.getPoint(); }};jlist.addMouseMotionListener(new MouseMotionAdapter(){ @Override public void mouseMoved(MouseEvent e){ int lastIndex = jlist.locationToIndex(lastPoint); Point current = e.getPoint(); int currentIndex = jlist.locationToIndex(current); if (currentIndex == lastIndex) return; ... // highlight lastPoint = current; }};