当前位置: 代码迷 >> J2SE >> JList中,当鼠标移动到某一项上时就高亮显示,该如何做这个事件
  详细解决方案

JList中,当鼠标移动到某一项上时就高亮显示,该如何做这个事件

热度:66   发布时间:2016-04-24 01:09:45.0
JList中,当鼠标移动到某一项上时就高亮显示,该怎么做这个事件?
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;    }};