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; } }; 就是这个想法。
hisList.addMouseMotionListener(new MouseMotionAdapter(){ @Override public void mouseMoved(MouseEvent e){ Point current = e.getPoint(); int currentIndex = hisList.locationToIndex(current); hisList.setSelectedIndex(currentIndex); } });
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;
}
};
就是这个想法。
hisList.addMouseMotionListener(new MouseMotionAdapter(){
@Override public void mouseMoved(MouseEvent e){
Point current = e.getPoint();
int currentIndex = hisList.locationToIndex(current);
hisList.setSelectedIndex(currentIndex);
}
});
jList.setSelectionForeground(Color.**);
试试吧,就知道这些